[Tutor] multithreading random()

Dick Moores rdm at rcblue.com
Tue Oct 10 10:02:49 CEST 2006


At 09:51 PM 10/9/2006, you wrote:
>On 10/10/06, Dick Moores <rdm at rcblue.com> wrote:
> > And another question. That page also says, "Almost all module
> > functions depend on the basic function random(), which generates a
> > random float uniformly in the semi-open range [0.0, 1.0). Python uses
> > the Mersenne Twister as the core generator. It produces 53-bit
> > precision floats and has a period of 2**19937-1." What is a 53-bit
> > precision float? Would that be something like a float accurate to 8
> > or 9 figures (dividing 53 by 8). Or what?
>
>Hi Dick,
>
>Have a look here: http://en.wikipedia.org/wiki/Double_precision
>and here: http://en.wikipedia.org/wiki/IEEE_floating-point_standard
>
>Basically, floating point numbers are of the form "x times 2**y",
>where x is a binary number between 1 and 10 (that's binary 10, decimal
>2).  53 bits means 53 binary digits of precision (including the
>initial 1).
>
>Does that help?

Well, before I dig into those references that I know are going to be 
difficult to understand, could you give me the bottom line about random()?

 >>> from random import random
 >>> print "%.17f" % random()
0.54188753195519013
 >>>

I can get what appears to be a random number precise(?) to 17 digits. 
How many base-10 digits would a "53-bit
precision float" have, if converted to base 10?

 >>> 2 ** 52
4503599627370496L
 >>> 2**53
9007199254740992L
 >>>

 >>> len(str(2**53))-1
15

So is the answer to my question something like len(str(2**53)) -1? 
(minus 1 because of the L in the long integer)

Thanks,

Dick





More information about the Tutor mailing list