I'd like to create n random 10-number-lists using python, and put these results in a list.
Below is my code:
from random import shuffle
def gen_random_list (num):
ran = []
k = [n for n in range(1, 11)]
for i in range(num):
shuffle(k)
ran.append(k)
return ran
The expected output should be something like:
[[4, 3, 10, 2, 8, 5, 7, 9, 6, 1],
[1, 3, 9, 6, 10, 4, 2, 8, 5, 7],
[4, 1, 3, 2, 9, 7, 8, 5, 6, 10]]
However, when I ran it in jupyter notebook, I got this:
[[4, 1, 3, 2, 9, 7, 8, 5, 6, 10],
[4, 1, 3, 2, 9, 7, 8, 5, 6, 10],
[4, 1, 3, 2, 9, 7, 8, 5, 6, 10]]
Which is just the repeatings of last random list.
screenshot in jupyter notebook
Could someone tell me where the problem is?
Thanks.
Aucun commentaire:
Enregistrer un commentaire