Home >Backend Development >Python Tutorial >How to Generate Random Integers Between 0 and 9 in Python?
Generating Random Integers from 0 to 9
Creating random numbers within a specific range is a common programming task. In Python, there are several ways to generate random integers, including the random.randrange() function, which provides a convenient solution for obtaining random values within a defined interval.
Answer:
The random.randrange() function takes two arguments: the upper limit and the lower limit (inclusive). To generate random integers between 0 and 9, specify 10 as the upper limit:
from random import randrange print(randrange(10))
This generates a random integer in the range [0, 9]. Multiple calls to randrange(10) will produce different random integers.
The above is the detailed content of How to Generate Random Integers Between 0 and 9 in Python?. For more information, please follow other related articles on the PHP Chinese website!