Let’s say we are given a list of numbers. We want to shuffle the list. We can do so easily in Python using the shuffle() function from the random module.
from random import seed from random import shuffle seed(1) data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] shuffle(data) print(data)
Here, we first use the seed() function to initialize the pseudo-random number generator. Then, we use the shuffle() function to shuffle the list in place. Please note that if we use the same seed value multiple times, then the shuffled list will be the same each time.
For example, here, we use the seed value 1. So, if we run the program multiple times, then the generated shuffled list will be the same each time.
The output of the above program will be like the following:
[7, 9, 10, 8, 6, 4, 1, 5, 2, 3]








































0 Comments