random changes

Raymond Hettinger vze4rx4y at verizon.net
Fri Aug 8 18:13:38 CEST 2003


"dan" <danbmil99 at yahoo.com> wrote in message
news:fbf8d8f2.0308071030.1f174d34 at posting.google.com...
> just a suggestion --
>
> next time the core RNG is changed, I think it would be useful to have
> an
> -oldrandom switch.  It is common practice in simulation projects to
> depend
> on the fact that your random numbers will come out the same if you use
> the same seed.  In bumping to 2.3 with the new Mersenne algorithm, I
> have no easy way of duplicating my old results.


It would have been helpful to included a sample call, the results, and
the version of Python you were using.  It looks like you were using
Py2.0 and upgraded to Py2.3.  This difference you are seeing came
version Py2.1 when WichmannHill's seed method was improved
(the upgrade to the Mersenne Twister has nothing to do with it):

"""
  random.py's seed() function is new.  For bit-for-bit compatibility with
  prior releases, use the whseed function instead.  The new seed function
  addresses two problems:  (1) The old function couldn't produce more than
  about 2**24 distinct internal states; the new one about 2**45 (the best
  that can be done in the Wichmann-Hill generator).  (2) The old function
  sometimes produced identical internal states when passed distinct
  integers, and there was no simple way to predict when that would happen;
  the new one guarantees to produce distinct internal states for all
  arguments in [0, 27814431486576L).
"""

So, to get your old results with Py2.3, try something like:

import random
rng = random.WichmannHill()
rng.whseed(12345)
for i in range(6):
    print rng.randint(1, 10)


Raymond Hettinger








More information about the Python-list mailing list