random module question

Raymond Hettinger python at rcn.com
Mon Jun 6 19:31:05 CEST 2005

>> Can I rely on the random.py module to produce the same series of
>> numbers for future/past versions of Python, given the same seed?

The answer is a qualified Yes.  While the core generator (currently the
Mersenne Twister algorithm) is subject to change across versions,
whenever we've updated the generator, a backward compatable version is
offered (random.WichmannHill for example).  So, it should always be
possible to recreate a series but you may have to change the calling
code to point to the correct generator.

>> Can I rely on it across different architectures and operating systems?

The current Mersenne Twister algorithm is guaranteed to produce the
same results across different architectures and operating systems.
That is evident from the test suite which verifies a bit-by-bit match
to a target test sequence (the test is expected to pass on all C boxes
with at least 53 bit floating point precision).

Of course, none of the above applies to random.SystemRandom which
accesses system generated entropy sources.

Raymond Hettinger

More information about the Python-list mailing list