Johannes Pfau wrote:
> Am Mon, 11 Jun 2012 13:09:26 -0500
> schrieb Andrei Alexandrescu <seewebsiteforem...@erdani.org>:
> 
> > On 6/11/12 12:32 PM, Joseph Rushton Wakeling wrote:
> > > On 11/06/12 18:15, Johannes Pfau wrote:
> > >> Could someone who's familiar with RNGs answer this question? This
> > >> seems to be important for st.uuid, we should get this right.
> > >
> > > In the Boost C++ implementation it certainly accepts a range as
> > > input:
> > >
> > > template<class It>
> > > void seed(It& first, It last)
> > > {
> > > int j;
> > > for(j = 0; j < n && first != last; ++j, ++first)
> > > x[j] = *first;
> > > i = n;
> > > if(first == last && j < n)
> > > throw std::invalid_argument("mersenne_twister::seed");
> > > }
> > >
> > > Some information on the seeding issue can be found here:
> > > http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html
> > 
> > We should have the same in std.random. Could anyone please initiate a 
> > pull request?
> > 
> > Thanks,
> > 
> > Andrei
> 
> Here's a first try:
> https://gist.github.com/2916360
> 
> Three questions:
> 
> * 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.

I simplified your code a bit.

enum n = 624;
enforce(range.length >= n, "MersenneTwisterEngine.seedRange: Input range didn't 
provide enough"
                           " elements");
uint mt[];
mt.length = n;
copy(range, mt);

But I'm unsure whether it still does what you intended.

Jens

Reply via email to