Take the 2-minute tour ×

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?

share|improve this question
Aside (just out of interest): why do you want this? –  larsmans Jan 9 '12 at 9:36
I need to generate two sequence of pseudo-random numbers on two run of a program, run that can be made by two people on two different machines. It's used for a generator of pseudo-cryptography "sheets" for a role-playing game. Don't worry, it's cryptography for a game, it has to be decipherable :) –  Laurent Jan 16 '12 at 10:30
I was hit by the change long ago (python 2.3). But it was detected, since I used a small test which checked the first numbers the random module creates. I suggest you use a test to check if the first numbers are the one you expect. –  guettli May 28 '13 at 8:50

3 Answers 3

up vote 5 down vote accepted

No, it doesn't. There's no such promise in the random module'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.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.

share|improve this answer

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).

share|improve this answer

Just as a heads up: in addition to the 2.3 change, python 3 gives numbers from python 2.x from randrange and probably other functions, even if the numbers from random.random are similar.

share|improve this answer

Your Answer


