Python Program to Generate Random Number

30
views
Random Number
(Last Updated On: November 13, 2018)

In this program, you’ll learn how to generate random number in Python.

To properly understand how to generate random number in python, you should have the knowledge of following Python programming topics:

  1. Python Input, Output and Import
  2. Python random module

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

Program to Generate a Random Number

# import the random module
import random

print(random.randint(0,9))

Output :

3

Note: we can get a different number as this Program generates any random numbers. and numbers will range from 0 – 9 because we have specified that.The syntax of this random function is:

random.randint(a,b)

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

Check Out This Related Programs below

Ask your questions and clarify your/others doubts on Program to Generate a Random Number by commenting or posting on our Forum. Python Documentation