python – Generate random integers between 0 and 9

python – Generate random integers between 0 and 9

Try:

from random import randrange
print(randrange(10))

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

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

python – Generate random integers between 0 and 9

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)

Leave a Reply

Your email address will not be published. Required fields are marked *