On 12/06/12 14:28, Jens Mueller wrote:
... and you'll get out each time the same values.  (Or instead of a
newly-defined generator you could just use rndGen as in my code
examples.)

Of course. But this behavior is clear from the documentation. Did it
surprise you? Passing a rng by value is fine I think.

_Is_ it clear? I would expect that if I create and use 3 samples as in my example code, then I would get 3 _different_ samples. But perhaps I'm too used to a C-style past where a single RNG is passed around to different functions within the thread.

Bear in mind that the behaviour is different depending on whether you pass an RNG or not. i.e. if you do

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

... you'll get 3 _different_ sets of values, whereas if you do

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

... you'll get out 3 times the same sample.

This could be resolved by making it so that if RandomSample is not passed a specified RNG, it sets the internally-stored RNG to be Random(unpredictableSeed).

Reply via email to