Generate a list of random numbers in python
Python Python Module (Article) Python Module (Program)
179
The randint() method can be used with for loop to generated a list of random numbers. To do so, we need to create an empty list, and then append the random numbers generated to the empty list one by one. Let's understand the following example.
Program:
import random rand_list = [] for i in range(0,10): n = random.randint(1,50) rand_list.append(n) print(rand_list)
Output:
[10, 49, 16, 31, 45, 21, 19, 32, 30, 16]
Explanation:
Using randint() method with for loop you can generate a list of random numbers.
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.