Mersenne Twister Seeding and UUIDs

Johannes Pfau nospam at example.com
Tue Jun 12 04:14:23 PDT 2012


Am Tue, 12 Jun 2012 11:48:11 +0200
schrieb Jens Mueller <jens.k.mueller at gmx.de>:

> > * As seed is a normal function right now, I can't overload it with a
> >   template. Is it safe to make the original seed a template as
> > well, so seedRange could be named seed, or would that break the API?
> 
> What do you mean by you can't overload it? Does it not compile? I
> think it should.
> 
> > * How should the seed array/range be generated? By repeatedly
> > calling unpredictableSeed?
> 
> No idea what is recommended from cryptographic point of view.
> 
> > * Is there a Range which repeatedly calls a function? Similar to
> >   repeat, but not repeating a value.
> 
> Here is one way to do it.
> seedRange(map!((a) => unpredictableSeed)(iota(0, 624)));
> Probably, there is a more straightforward way.

Thanks, that's good enough. It would be even better if it was an
infinite range, though.

> I simplified your code a bit.
> 
> enum n = 624;
> enforce(range.length >= n, "MersenneTwisterEngine.seedRange: Input
> range didn't provide enough" " elements");

I can't really use .length, the code has to work with infinite ranges
as well.

> uint mt[];
> mt.length = n;
> copy(range, mt);
> 
> But I'm unsure whether it still does what you intended.

Well, the code was a simple 1:1 port of the boost function and as I'm
not familiar with RNGs I don't really want to change (and probably
break) it.

> 
> Jens




More information about the Digitalmars-d mailing list