How to Generate a Random Number in Python Program ?

17-Jun-2021

.

Admin

How to Generate a Random Number in Python Program ?

Hi Guys,

In this blog, I will show you how to generate random number in python. . if you have question about python generate random 6 digit number then i will give simple example with solution. you will learn how to generate random unique number in python.

In this post, i will give you two example where you can generate random number with python and you can learn how to generate random unique number in python.

Here I will give simple example for generate random number using python program. So let's see the bellow example:


Example 1 :

test.py

# Program to generate a random number 6 digit

# importing the random module

import random

print(random.randint(0,999999))

Output :

786271

Example 2 :

test.py

# Program to generate a random number 0 to 9

# importing the random module

import random

print(random.randint(0,9))

Output :

8

Run python file:

python test.py

It will help you....

#Python