Skip to content
Home » Generate List of random numbers using Loop : Python

Generate List of random numbers using Loop : Python

We should use the for loop with the randint() method to generate a list of random numbers. To do so, we must first create an empty list, after which we must add the generated random numbers one by one to the empty list.

import random  
ran_list = []
for i in range(0,5): 
    #generating random numbers 
    n = random.randint(10,150)  
    ran_list.append(n)  
print(ran_list) 

Output:

[28, 79, 32, 44, 142]

Also Read:

randint() Python

Generate Random Number in Python