random number between -maxint and +maxint

Emile van Sebille emile at fenx.com
Sun Mar 11 18:57:49 EST 2001


Don,

I think this may do it, but I'm not sure if it stays random or catches the
endpoint properly.  Hopefully someone with more theory will jump in with an
answer.

import random, sys
print random.randrange(-sys.maxint/2, sys.maxint/2)*2 + random.choice([0,1])

Emile van Sebille
emile at fenx.com

"Dan Parisien" <dan at eevolved.com> wrote in message
news:K2Sq6.360684$Pm2.5406628 at news20.bellglobal.com...
> I can't figure out a good way to do it, does anyone know a better solution
> than
>
> from whrandom import whrandom
> rand = whrandom()
> max = 2**30 + (2**30-1) #one less than 2**31
> randomnumber = rand.randrange(0, max) - rand.randrange(0, max)
>
> thank you for your time,
> Dan





More information about the Python-list mailing list