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.

Reply via email to