Python Program to Generate a Random Number in 3 easy steps

In this program, we are going to make a python program which will generate random number.

In this program, we are going to make a python program which will generate random number.

Python program to generate a random number between 1 and 100

We will import random module in our program. We will use a predefined function called randint.

import random
randomNumber = random.randint(1, 100)
print(randomNumber)

Let suppose you want to find a random between 2 numbers x and y(both inlcusive), then you will use random.randint(x, y);



Random number in dice program python

import random
red = random.randint(1, 6)
print(res)

If you want to generate random number without using random module, you can read on stackoverflow about it.

Steps to write a program to generate random number in python in 3 easy steps

  1. Importing the random Module.
    import random
    
  2. Now we will select the interval. Random number will be fall in the provided interval.
    random.randint(1, 10)
  3. Now you can print the number returned in step 2.

This is all about Python Program to Generate a Random Number. If you have any doubts regarding this program, let me know in the comment section.

Post a Comment

Please do not enter any spam link in the comment box.