digitalmars.D.learn - Predictable seed for pseudo-random number generation
- Joseph Rushton Wakeling (18/18) Jul 20 2012 Hello all,
Hello all, Often when writing simulations with pseudo-random number generation you want to be able to use a predictable seed for testing purposes, e.g. to confirm whether an alteration to the code produces changes in output. In a single-threaded piece of code this is easy -- one can just put rndGen.seed(/* my chosen seed here*/); ... in the main() function. But what about multithreaded code? rndGen is (by definition) thread-global, and so will be separately seeded in each thread. Again, it's surely possible to put in place something like the above in the controller function for each thread; perhaps rndGen.seed(baseSeed + threadID); ... but it would be nice if there was a simpler way of ensuring that all default RNG seeds will be predictable, without damaging the independence of the random number sequences in different threads. On a related note, is it possible to override the default random number generator with another type? Thanks and best wishes, -- Joe
Jul 20 2012