random 64-bit int

Bengt Richter bokr at oz.net
Thu Jul 25 18:17:02 EDT 2002


On Thu, 25 Jul 2002 17:07:21 -0400, "Tim Peters" <tim at zope.com> wrote:

>[Jeff Davis]
>> ...
>> random() isn't really all that random either, since it is only zero to
>> one and a conversion to a float loses a lot of information (I think...
>> let me know if I'm mistaken).
>
>A Python float is a C double, which on most boxes has 53 bits of precision.
>That means, e.g., that there are 2**53 distinct Python floats in the range
>[0.5, 1.0) alone.  Also 2**53 distinct Python floats in the range [0.25,
>0.5) alone; etc.  That's a lot of floats.  Python's Wichmann-Hill generator
It's a lot of floats, but I think your number should be 52, for bits representing
the fraction bits below the single implicit bit that represents 0.5 or 0.25 etc.

>has only about 45 bits of internal state, and no information is lost in
>representing one of those states as a Python float.
>
>A direct and quicker pure-Python method of generating random N-bit ints can
>be found here:
>
>    http://www.faqts.com/knowledge_base/view.phtml/aid/4406
>
>

Regards,
Bengt Richter



More information about the Python-list mailing list