Not-so-unpredictable seed?
Joseph Rushton Wakeling
joseph.wakeling at webdrake.net
Tue Apr 17 20:47:16 PDT 2012
Can anyone explain to me why, when I compile & run this code, the two samples
seeded with the unpredictableSeed always come out with the same starting value?
//////////////////////////////////////////////////////////////
import std.random, std.range, std.stdio;
void main()
{
auto s = randomSample(iota(0, 100), 5);
foreach(uint i; s)
writeln(i);
writeln();
auto s2 = randomSample(iota(0, 100), 5);
foreach(uint i; s2)
writeln(i);
writeln();
auto urng3 = Random(unpredictableSeed);
auto s3 = randomSample(iota(0, 100), 5, urng3);
foreach(uint i; s3)
writeln(i);
writeln();
auto urng4 = Random(unpredictableSeed);
auto s4 = randomSample(iota(0, 100), 5, urng4);
foreach(uint i; s4)
writeln(i);
}
//////////////////////////////////////////////////////////////
In fact it's not just the unpredictable seed -- no matter what seed I pass, so
long as an RNG is passed to the randomSample function, the first entry is always
the same.
Note that this is Phobos' randomSample, not my tweaked implementation.
Anyone got any ideas?
More information about the Digitalmars-d-learn
mailing list