Generate random integers between 0 and 9
Solution 1:
Try:
from random import randrange
print(randrange(10))
Docs: https://docs.python.org/3/library/random.html#random.randrange
Solution 2:
import random
print(random.randint(0,9))
random.randint(a, b)
Return a random integer N such that a <= N <= b.
Docs: https://docs.python.org/3.1/library/random.html#random.randint
Solution 3:
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)
Solution 4:
from random import randint
x = [randint(0, 9) for p in range(0, 10)]
This generates 10 pseudorandom integers in range 0 to 9 inclusive.