Random...

Tim Peters tim.one at comcast.net
Mon Mar 25 13:15:00 EST 2002


[FREDRIK HULDTGREN]
> I want to generate random numbers, very large random numbers. If I use
> randrange() I get an out of bounds error since it only supports numbers
> up to (2**31)-1. However, I can use uniform(), but then I get the number
> returned in 7.9655120654553743e+018 or something simaler, and I would
> rather have it in a "L" format(796551206545537430183218312890381031L).
> How do I do this?

You don't:  you're looking for a miracle.  A uniform() has no more than 53
significant bits (the limit of a Python float on most boxes), and the
underlying Wichmann-Hill generator can't make more than about 45 of those
even arguably "random".  You can't magically increase the amount of
available randomness via multiplying by a large integer.

So you need a different approach.  Here's one:

http://www.faqts.com/knowledge_base/view.phtml/aid/4406/fid/546





More information about the Python-list mailing list