whrandom.randint(): no LONGs?

Gerrit Holl gerrit.holl at pobox.com
Sat Sep 11 17:07:17 EDT 1999


Gerrit Holl (I) asked:
> > whrandom.randint() always tries 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...

Tim Peters has given the excellent answer:
> 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.
> 

I think I understand. I haven't had mathematical algorithems about random
things at school yet, but I don't think I'll need it to understand this,
except that I don't know the difference between the illusion of random longs
and real random longs, but for now, that's not important for me.

> 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.
> 

I don't think I'll need it, but thanks for the information.

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

regards,
Gerrit.
-- 
Unix is easy: type 'man man' and the rest comes of itself.




More information about the Python-list mailing list