BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Python Program to Generate a Random Number

Last Updated: July 6, 2021 by Chaitanya Singh | Filed Under: Python Examples

In this tutorial, you will learn how to generate a random number in Python.

We will use randint() function of random module to generate a random number between a given range. To use this function, we must import random module in our python program.

Syntax of randint() function

random.randint(x,y)

This will generate a random number in the range of x to y, x and y are inclusive in the range, which means the generated random number lies in the range x <= random number <= y

Program to Generate a Random Number in Python

In this program we are generating a random number in the range of 0 to 100 (0 & 100 are inclusive in the range). We are importing the random module so that we can use the randint() function, which is defined in the random module.

# Program to generate a random number between 0 and 100

# importing the random module
import random

print('Generated Random Number:',random.randint(0,100))

Output:

Python Program to Generate a random number

Related examples:

  • Java program to generate random number – Example
  • SQL Select Random Rows from Table
  • Python Program to Print Calendar
  • Python Program to add Digits of a number

Top Related Articles:

  1. Python Program to Check if a Number is Positive Negative or Zero
  2. Python Program to Find ASCII Value of a Character
  3. Python Program to Find Largest among Three Numbers
  4. Python Program to Convert Celsius To Fahrenheit and Vice Versa
  5. Python program to reverse a String using Recursion

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap