Python Random number generator

How do I generate a random number?
This is my code:

Help Me.

2 Likes
from random import randint
print randint(1, 10) #will print a random number between 1 and 9(inclusive)

or you can just:

import random
print random.randint(1, 10) #will print a random number between 1 and 9(inclusive)

Hope this helps :grinning:

1 Like

Not to be confused with randrange which excludes the stop value, randint includes both the low and the high arguments. That is,

random. randint ( a , b )

Return a random integer N such that a <= N <= b .

2 Likes