random module question

R

Roose

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? Can I rely on it
across different architectures and operating systems?

I looked at the docs and couldn't find this stated anywhere. My feeling is
yes, but it's a fairly big claim so I want to make sure.

R
 
P

Paul Rubin

Roose said:
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? Can I rely on it
across different architectures and operating systems?

I looked at the docs and couldn't find this stated anywhere. My feeling is
yes, but it's a fairly big claim so I want to make sure.

I do not think you should rely on this. It uses a very specific
algorithm (Mersenne Twister) which is written in C and is nonstandard,
and future Python implementers shouldn't be expected to implement the
exact same algorithm. It's probably already unavailable in Jython.

See SF bug 917055 for some further discussion.
 
R

Raymond Hettinger

Can I rely on the random.py module to produce the same series of
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.



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
 
P

Paul Rubin

Raymond Hettinger said:
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).

Is Mersenne Twister currently available at all in Jython, for example?
 
R

Roose

Raymond said:
The answer is a qualified Yes. While the core generator (currently

Thanks! That is the answer I'm looking for.

And to Paul Rubin, it is a good point that Jython might not support it, but
at this point it doesn't interest me. The program is only for myself
anyway.

R
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,241
Messages
2,571,219
Members
47,850
Latest member
StewartTha

Latest Threads

Top