range question, compared to Smalltalk

Frank Buss fb at frank-buss.de
Tue Aug 27 17:00:10 EDT 2002


Hi,

I'm a Python newbie, so forgive me, if I'm asking stupid questions :-)

If I write this:

import random
random.choice(range(0, 100000000))

it took very long to calculate a random number (I know, I can use 
"random.randint(0, 1000000000)"). Looks like "range" returns a normal 
list. Why not an object?

If I write this in Smalltalk:

(0 to: 1000000000000) at: 12345678901

I get the result immediately. If I write "range(0, 1000000000)" in Python 
I'll get a Memory Error.

Another question: How can I generate very high random numbers? If I write 
"random.randint(0L, 100000000000000L)" I'll get an overflow error. I 
thought everything is an object and I can use small and long integers as I 
want.

-- 
Frank Buß, fb at frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de



More information about the Python-list mailing list