Ranges and random numbers -- again

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Tue Jun 18 07:32:02 PDT 2013


On 06/18/2013 03:16 PM, H. S. Teoh wrote:
> No, I just looked at the source code, and there is no call to .save in
> the ctor. This is just another symptom of RNGs being passed by value: t1
> and t2 are operating on two copies of rndGen passed by value. Were they
> passed by reference, this wouldn't have been a problem.

You're right, it was my mistake -- I was scanning/searching the source code too
quickly and a search for 'this(' took me into another struct without me realizing.

> Just make RNGs passed by reference, and the above problem will not
> happen.

That was the conclusion I also came to after monarch_dodra's examples.  However,
I'm still concerned about circumstances where an algorithm might choose to
operate on a .save copy rather than on the original range -- this could result
in unnoticed statistical correlations.

Can I reasonably assume that no D language/runtime/standard library algorithm
would do that?  And if not, what are the examples where a .save is consumed
instead of the original range?


More information about the Digitalmars-d mailing list