Predictable seed for pseudo-random number generation

Jonathan M Davis jmdavisProg at gmx.com
Fri Jul 20 10:59:02 PDT 2012


On Friday, July 20, 2012 19:52:17 Joseph Rushton Wakeling wrote:
> On a related note, is it possible to override the default random number
> generator with another type?

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. So, you could put it in a version(unittest) block if you want it 
specifically for unit testing.

However, std.random.rndGen just returns std.random's default random number 
generator, and you can't mess with it. If you really want to be able to have 
control over the type or seed of the random number generator that you're 
using, you should declare your own. rndGen is provided merely for convenience, 
and it's simple enough to use other random number generators from std.random 
if just using the default doesn't fit your needs.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list