Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: random changes

Reply
Thread Tools

Re: random changes

 
 
Raymond Hettinger
Guest
Posts: n/a
 
      08-08-2003

"dan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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




 
Reply With Quote
 
 
 
 
dan
Guest
Posts: n/a
 
      08-10-2003
"Raymond Hettinger" <(E-Mail Removed)> wrote in message news:<S_PYa.73$(E-Mail Removed)>...

> 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)
>

that worked, thanks
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Math.random() and Math.round(Math.random()) and Math.floor(Math.random()*2) VK Javascript 15 05-02-2010 03:43 PM
random.random(), random not defined!? globalrev Python 4 04-20-2008 08:12 AM
Random desktop layout changes (W98SE) Karl Engel Computer Support 3 08-23-2005 10:17 PM
Random NOt random? Darren Clark ASP .Net 3 06-24-2004 05:23 PM
Re: random changes Andrew Dalke Python 2 08-08-2003 08:36 AM



Advertisments