RandomSample with specified random number generator

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Thu Jun 14 15:55:38 PDT 2012


On 14/06/12 21:27, Jens Mueller wrote:
> What are the advantages of the above in regard to
> auto randomSample(R, Random)(R r, size_t n, Random r = 
> Random(unpredictableSeed))
> ?
> Is it because you got bitten that the generators are passed by 
> value?

It's because it relies on the user understanding that they have 
to _seed_ any RNG they pass -- they can't just e.g. pass the RNG 
of the current thread they are in, because then they will have 
correlations between the sample and any subsequent random numbers 
they generate.  So the possibility to do this:

     sample = randomSample(iota(0, 100), 5, rndGen);

... should probably be disallowed on grounds of safety.

Now, since you HAVE to seed the RNG in order to take a sample 
safely, you might as well make the _seed_ the thing which is 
passed, rather than the RNG.


More information about the Digitalmars-d mailing list