If I shuffle a small list using python's random.shuffle
, I'm getting also unshuffled results.
import random
for i in range(10):
ori = [1, 2, 3]
per = ori[:]
random.shuffle(per)
print i, per, (per == ori) or ""
Here is a sample output:
0 [1, 3, 2]
1 [1, 2, 3] True
2 [3, 1, 2]
3 [2, 3, 1]
4 [1, 2, 3] True
5 [2, 3, 1]
6 [3, 2, 1]
7 [2, 1, 3]
8 [2, 1, 3]
9 [2, 1, 3]
I understand that this must necessarily be the case, after looking into the algorithm details [1], [2]. But I really want get a small unsorted list (say 3 to 6 items) programmatically.
What do you think is the best approach to do this?