Ranges and random numbers -- again

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Mon Jun 17 15:54:18 PDT 2013


On 06/17/2013 11:34 PM, monarch_dodra wrote:
> I don't think you should pass rndGen to adapter ranges if you want any kind of
> deterministic behavior.

Actually, _passing_ rndGen with the current value semantics _will_ produce
deterministic behaviour.  The problem is that it's statistically unsafe as the
copy-by-value means that the results of the adapter ranges will correlate with
subsequent other uses of rndGen.

> You should really give such ranges their own new
> generator, eg:
> 
>    auto sample = randomSample(iota(100), 5, Random(unpredictableSeed));

I did discuss that in my longer email.  I consider this to be statistically
unsound because you can't guarantee that the results of
Random(unpredictableSeed) will be statistically independent from the results of
other random number generation activities in your program (a risk which
increases with the number of random samples you generate in your program).

It's also undesirable because relying on the user to be virtuous and generate a
new, unpredictably seeded RNG is (to my mind) too trustworthy.

If we consider D's goal to be safe-by-default, where statistics are concerned
that should mean that the easy thing to do is also statistically "safe".


More information about the Digitalmars-d mailing list