Size of integers (2**32-1)
Peter Hansen
peter at engcorp.com
Sun Feb 10 12:50:40 EST 2002
Paul Rubin wrote:
>
> Thomas Guettler <st-newsgroups at thomas-guettler.de> writes:
> > The module random contains a lot of functions. I think getting a
> > random 32 random number is needed often.
> >
> > randrange(0,2147483647) is not a 32 Bit random number because
> > 2**32-1 is 4294967295.
>
> Woops, sorry, I misread 2**32-1 as 2**31-1 which is the largest
> 32-bit positive integer. 2**32-1 is an overflow if you use 32 bit
> ints. I guess you could try random(-2147483648, 2147483647)
> if you want all 32 bits random. Alternatively you could try
> (random(0,65536) << 16 | random(0,65536))
Unfortunately, random.randrange(-2147483648, 2147483647) would
exclude 2147483647. randrange(1) produces only zero....
More information about the Python-list
mailing list