In this example, you will learn to generate a random number in Python.
To understand this example, you should have the knowledge of the following Python programming topics:
To generate random number in Python, randint() function is used. This function is defined in random module.
Source Code
# Program to generate a random number between 0 and 9 # importing the random module import random print(random.randint(0,9))
Output
5
Note that 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 a number N in the inclusive range [a,b], meaning a <= N <= b, where the endpoints are included in the range.
Related posts:
Python Program to Display the multiplication Table
Python String lstrip()
Deep Learning with Python - Francois Cholletf
Python len()
Python Operators
Python Program to Find the Factorial of a Number
Python Program to Find the Largest Among Three Numbers
Python Program to Convert Two Lists Into a Dictionary
Python Program to Check Leap Year
Python dir()
Python String lower()
Python Program to Make a Flattened List from Nested List
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python String islower()
Python Set issubset()
Python Program to Safely Create a Nested Directory
Python break and continue
Python id()
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python RegEx
Python Anonymous / Lambda Function
Python String isalnum()
Python Program to Illustrate Different Set Operations
Python String isalpha()
Python for Loop
Python Program to Access Index of a List Using for Loop
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python Deep Learning Cookbook - Indra den Bakker
Python Program to Find ASCII Value of Character
Python Program to Convert Bytes to a String