Generate random integers between 0 and 9

aneuryzm picture aneuryzm · Oct 22, 2010 · Viewed 2M times · Source

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

Answer

kovshenin picture kovshenin · Oct 22, 2010

Try:

from random import randrange
print(randrange(10))

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