[Tutor] multithreading random()

John Fouhy john at fouhy.net
Tue Oct 10 22:48:11 CEST 2006


On 10/10/06, Dick Moores <rdm at rcblue.com> wrote:
> 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)

The string representation of longs doesn't include the 'L':

>>> str(9999999999999999999L)
'9999999999999999999'
>>> repr(9999999999999999999L)
'9999999999999999999L'

I think the answer is "approximately, yes".  But you have to be a bit
careful with talking about floating point numbers in terms of
decimals.  eg:

>>> 1.1
1.1000000000000001

-- 
John.


More information about the Tutor mailing list