Predictable seed for pseudo-random number generation

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Fri Jul 20 15:32:05 PDT 2012


On 20/07/12 19:59, Jonathan M Davis wrote:
> As long as rndGen isn't called with its full path (std.random.rndGen), any
> module which uses it could declare its own rndGen, and it would be used
> instead of std.random's, in which case you could do whatever you want with its
> type or seed.

I did consider that, but I found myself wondering what would happen if I did 
something like this:

///////////////////////////////////////////////////////////
import std.random;

@property ref MyRNG rndGen()
{
     // etc. ...
}


void main()
{
     auto s = randomSample(iota(0, 100), 10);
     // and do something with s
}
///////////////////////////////////////////////////////////

Calling randomSample like this ought to involve rndGen; but given that 
randomSample is in std.random, would it use my self-defined rndGen, or that from 
std.random?

OK, I probably should and certainly could have tested this myself ... :-)  I was 
just wondering if there was a _trivial_ way to override the default RNG type.


More information about the Digitalmars-d-learn mailing list