Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

random module question

0 views
Skip to first unread message

Roose

unread,
Jun 5, 2005, 8:40:11 PM6/5/05
to
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


Paul Rubin

unread,
Jun 5, 2005, 8:57:32 PM6/5/05
to

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.

Raymond Hettinger

unread,
Jun 6, 2005, 1:31:05 PM6/6/05
to
>> 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

Paul Rubin

unread,
Jun 6, 2005, 3:14:09 PM6/6/05
to
"Raymond Hettinger" <pyt...@rcn.com> writes:
> >> 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).

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

Roose

unread,
Jun 7, 2005, 2:06:58 AM6/7/05
to
Raymond Hettinger wrote:
> 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


Raymond Hettinger

unread,
Jun 7, 2005, 3:07:16 AM6/7/05
to
>> Is Mersenne Twister currently available at all in Jython, for example?

Googling for "java mersenne twister" provides multiple hits including:

http://www.axlradius.com/freestuff/Free.htm#MT


Raymond

0 new messages