Python – Generate random integers between 0 and 9

integerpythonrandom

How can I generate random integers between 0 and 9 (inclusive) in Python?

For example, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Best Solution

Try:

from random import randrange
print(randrange(10))

Docs: https://docs.python.org/3/library/random.html#random.randrange