Python Program to Generate a Random Number

Generate a Random Number

To generate random number, randint() function is used. This function is defined in random module.

CODE OUTPUT
# Program to get a random number between 0 and 9

# import the random module

import random

print(random.randint(0,9))

5
we may get different output because this program generates random number in range 0 and 9. The syntax of this function is:

random.randint(a,b)

This returns N in the inclusive range [a,b], meaning a <= N <= b, where the endpoints are included in the range.

Questions