Python Program to Generate a Random Number
Python Python Module (Article) Python Module (Program)
171
In Python programming, you can generate a random integer, doubles, longs etc . in various ranges by importing a "random" class.
In Python, we can generate a random integer, doubles, long, etc in various ranges by importing a "random" module. In the following example, we will learn how to generate random numbers using the random module.
Syntax:
First, we have to import the random module and then apply the syntax:
import random
Generating a Random Number
The random module provides a random() method which generates a float number between 0 and 1. Let's see the following example.
Program:
import random n = random.random() print(n)
Output:
0.7632870997556201 If we run the code again, we will get the different output as follows. 0.8053503984689108
Explanation:
This Particular section is dedicated to Programs only. If you want learn more about Python. Then you can visit below links to get more depth on this subject.