tags:

views:

111

answers:

2

How can I generate random integers numbers between 0<9 (included extremes) in python ?

i.e. 0 1 2 3 4 5 6 7 8 9

thanks

+1  A: 

Try this:

from random import randrange, uniform

# randrange gives you an integral value
irand = randrange(0, 10)

# uniform gives you a floating-point value
frand = uniform(0, 10)
Andrew Hare
"(included extremes)" `randrange(0, 9+1)`
eumiro
Whoops - nice call.
Andrew Hare
+4  A: 

Try:

from random import randrange
print randrange(10)

More info: http://docs.python.org/library/random.html#random.randrange

kovshenin
@Kovshenin What about randint ?
Patrick
Yeah, `randint(0,10)` will work fine too.
kovshenin