whrandom.randint(): no LONGs?

Tim Peters tim_one at email.msn.com
Sat Sep 11 16:29:51 EDT 1999


[Gerrit Holl]
> whrandom.randint() always try to convert the given arguments to a
> integer. Why?
> I'm not able to use Longs now. I don't require it directly, but
> it might be a useful thing to know the "why". I can learn from it...

It's a good question!  The "deep" reason is that the method used by whrandom
to create the illusion of randomness has limited precision.  Using this
method to ask for a random choice from among 2**15 things works pretty well
for most purposes; but using it to ask for a random choice from among
2L**150 things would work terribly for many purposes.  Creating the illusion
of random longs requires a different approach altogether, so rather than
give you garbage results Python raises an error.

If you get to the point where you need pseudo-random longs, I posted a
LongRan.py module about a year ago that can do it.

whrandom-knows-its-limitations-so-it's-smarter-than-us-ly y'rs  - tim






More information about the Python-list mailing list