random module gives same results across all configurations?
pavlovevidence at gmail.com
Wed Mar 4 11:05:07 CET 2009
On Mar 4, 12:33 am, "Diez B. Roggisch" <de... at nospam.web.de> wrote:
> > So far I get the same results under Mac OS X, Windows, and Linux
> > (Google App Engine). I'm particularly interested in getting the same
> > results under the Google App Engine even as Google upgrades its
> > servers over time.
> I just had a look into the python source - and I was wrong, it appears
> random is implemented as part of the python c modules itself.
The standard library's rand and srand functions had a reputation for
being notoriously bad on a lot of platforms. I remember back in the
day the advice was (and probably still is a good idea today) that if
you needed a small random number, never mask out the high bits, but
instead divide a random number from the full range by .
I never actually tested rand, but if it's as bad as they said it was,
it's a good thing Python doesn't use it.
> So chances are good that unless this module changes, you get a stable
> But I'd not advise to rely on that. Why do you want that anyway?
All kinds of reasons. For a unit test you might want a repeatable
sequence, or even a canned fake-random sequence. Sometimes random
sequences are used to generate data, and you might want to give the
user power to regenerate the same data by seeding the PRNG with the
same seed. (A well-known example is "Free Cell", where the game
number is just an RNG seed.)
More information about the Python-list