Generate a Random Number within a Given Range

Python Python Module (Article) Python Module (Program)

171

Python random module provides the randint() method that generates an integer number within a specific range. We can pass the two numbers as arguments that defines the range. Let's understand the following example.

Program:

import random  
n = random.randint(0,50)  
print(n)  

Output:

40

Explanation:

Another Example

import random  
n = random.randint(100, 200)  
print(n)  

Output

143

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.