I need to generate a controlled sequence of pseudo-random numbers, given an initial parameter. For that I’m using the standard python random generator, seeded by this parameter. I’d like to make sure that I will generate the same sequence across systems (Operating system, but also Python version).
In summary: Does python ensure the reproducibility / portability of it’s pseudo-random number generator across implementation and versions?
No, it doesn’t. There’s no such promise in the
randommodule’s documentation.What the docs do contain is this remark:
So a different RNG was used prior to Python 2.3.
So far, I’ve been using
numpy.random.RandomStatefor 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) fromhashlib.