473,385 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

random module question

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
Jul 19 '05 #1
5 1611
"Roose" <b@b.b> 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? 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.
Jul 19 '05 #2
>> 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

Jul 19 '05 #3
"Raymond Hettinger" <py****@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?
Jul 19 '05 #4
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
Jul 19 '05 #5
>> 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

Jul 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: Paul Rubin | last post by:
http://www.nightsong.com/phr/python/sharandom.c This is intended to be less predicable/have fewer correlations than the default Mersenne Twister or Wichmann-Hill generators. Comments are...
3
by: Rob B | last post by:
Hello, I am just starting to learn Python and was writing a simple script on my machine (Mac OS X 10.3.4), but I can't seem to import the random module: #!/usr/bin/env python import random
1
by: Will McGugan | last post by:
Hi, If I retrieve the hash of an integer, will it always return the same value across platforms? This reason I ask is that I want to produce a sequence of pseudo random numbers using the...
10
by: Glenn Wilson | last post by:
I have a quick Question and I Hope some one can help or at least explain. What is happening is that I am trying to use random numbers in an application, as per the sample test code below. When I...
14
by: DataSmash | last post by:
Hi, When I import the random module at the python interpreter, it works fine: >>> import random >>> x = random.randint(1,55) >>> print x 14 >>> BUT, when I put the same code in a python...
13
by: porterboy76 | last post by:
If you only use a 32 bit seed for a random number generator, does that mean you can only ever produce a maximum of 2^32 (approx 4 billion) different sequences? What about the Mersenne Twister,...
6
by: Alan Isaac | last post by:
Running test.py will print False. Is this expected/desirable? Thanks, Alan Isaac %%%%%%% test.py %%%%%%%%%%% from random import seed, getstate seed(217) x = getstate()
39
by: Alan Isaac | last post by:
This may seem very strange, but it is true. If I delete a .pyc file, my program executes with a different state! In a single directory I have module1 and module2. module1 imports random and...
3
by: Andrew F | last post by:
I'm a linux user and I just upgraded from 2.1 to 2.5 and changed the location of a number of libraries and tools. So far I've tracked most errors, but this one has me scratching my head : $...
11
by: Alex | last post by:
Hi everybody, I wonder if it is possible in python to produce random numbers according to a user defined distribution? Unfortunately the random module does not contain the distribution I need...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.