SHA-based subclass for random module
Paul Rubin
http
Sun Mar 21 02:51:06 CET 2004
anton at vredegoor.doge.nl (Anton Vredegoor) writes:
> I wonder why it is necessary to do the bit twiddling once one has
> chosen to multiply by a fraction instead of directly putting the bits
> inside a float. If 1.0 / 2**53 is just some arbitrary value (and why
> not: A floats' smallest value is a lot smaller than that?) then we can
> generate integers of other sizes and divide them by other floats, for
> example:
I think life gets very complicated once you start trying to generate
denormalized floats. They aren't uniformly distributed on the unit
interval, so if you make random numbers by dividing uniformly
distributed integers by some constant, you'll get way too many
denorms. If your application is using so many random numbers that it
much chance of ever seeing one below 2**-53, maybe you need to use
extended precision or something. Note this whole thing gets into the
precise properties of machine floats, and Python in principle is not
supposed to be IEEE-dependent. (The magic number 2**-53 is an IEEE
artifact).
More information about the Python-list
mailing list