Reproducibility of python pseudo-random numbers across systems and versions?
Not necessarily.
As described in the documentation, the random
module has used the Mersenne twister to generate random numbers since version 2.3, but used Wichmann-Hill before that.
(If a seed is not provided, the method of obtaining the seed also does depend on the operating system, the Python version, and factors such as the system time).
No, it doesn't. There's no such promise in the random
module's documentation.
What the docs do contain is this remark:
Changed in version 2.3: MersenneTwister replaced Wichmann-Hill as the default generator
So a different RNG was used prior to Python 2.3.
So far, I've been using numpy.random.RandomState
for reproducible pseudo-randomness, though it too does not make the formal promise you're after.
If you want full reproducibility, you might want to include a copy of random
's source in your program, or hack together a "P²RNG" (pseudo-pseudo-RNG) from hashlib
.