Ranges and random numbers -- again

monarch_dodra monarchdodra at gmail.com
Mon Jun 17 15:34:11 PDT 2013


On Monday, 17 June 2013 at 22:18:44 UTC, Joseph Rushton Wakeling 
wrote:
> On 06/17/2013 09:36 PM, monarch_dodra wrote:
>> Good analysis but (sorry) I think you are on the wrong track.
>> 
>> One of the major problems in std.random is that the ranges use 
>> value semantics.
>> This means they are *saved* whenever they are copied, as 
>> opposed to just
>> referenced. This creates the problems you have mentioned, and 
>> even more.
>
> I agree that the fact that pseudo-random number generators use 
> value semantics
> is a serious problem, and I was thinking of our previous 
> discussions in
> preparing these remarks.

I didn't even realize you were part of that thread :/ Sorry about 
that.

> On the contrary, consider the SimpleRandomRange -- or 
> RandomSample -- with a
> specified RNG that has reference semantics.  You'll get a 
> different sequence
> each time you iterate over it, and .save will not enable you to 
> reproduce the
> sequence.

I don't think you should pass rndGen to adapter ranges if you 
want any kind of deterministic behavior. You should really give 
such ranges their own new generator, eg:

    auto sample = randomSample(iota(100), 5, 
Random(unpredictableSeed));

That said, it would help even more if we had something *even* 
simpler, such as:
"Random random()" or "Random newRandomRange()", and then have the 
more idiomatic:

    auto sample = randomSample(iota(100), 5, newRandomRange());


More information about the Digitalmars-d mailing list