Here is a piece of code I wrote as an attempt to examine the behavior of seed numbers in Python's random.shuffle()
from random import shuffle
seed_list = [ 0.0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35,
0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75,
0.8, 0.85, 0.9, 0.95
]
last_list = list(range(0, 10))
for seed in seed_list:
num_list = list(range(0, 10))
shuffle(num_list, lambda:seed)
print("Seed", str(seed)+":\t", num_list, num_list==last_list)
last_list = num_list
And the output looks something like this:
:~$ python3 test_shuffle.py
Seed 0.0: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] False
Seed 0.05: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] True
Seed 0.1: [9, 2, 3, 4, 5, 6, 7, 8, 0, 1] False
Seed 0.15: [6, 2, 3, 4, 5, 0, 7, 8, 9, 1] False
Seed 0.2: [4, 9, 3, 0, 5, 6, 7, 8, 1, 2] False
Seed 0.25: [3, 7, 0, 4, 5, 6, 1, 8, 9, 2] False
Seed 0.3: [9, 6, 0, 4, 5, 1, 7, 8, 2, 3] False
Seed 0.35: [5, 0, 8, 4, 1, 6, 7, 2, 9, 3] False
Seed 0.4: [9, 0, 7, 1, 5, 6, 2, 8, 3, 4] False
Seed 0.45: [8, 0, 6, 1, 5, 2, 7, 3, 9, 4] False
Seed 0.5: [0, 9, 1, 7, 2, 6, 3, 8, 4, 5] False
Seed 0.55: [0, 9, 1, 7, 2, 6, 3, 8, 4, 5] True
Seed 0.6: [0, 9, 1, 2, 8, 3, 7, 4, 5, 6] False
Seed 0.65: [0, 9, 1, 2, 7, 3, 4, 8, 5, 6] False
Seed 0.7: [0, 1, 9, 2, 3, 8, 4, 5, 6, 7] False
Seed 0.75: [0, 1, 2, 9, 3, 4, 5, 8, 6, 7] False
Seed 0.8: [0, 1, 2, 3, 9, 4, 5, 6, 7, 8] False
Seed 0.85: [0, 1, 2, 3, 4, 9, 5, 6, 7, 8] False
Seed 0.9: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] False
Seed 0.95: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] True
According to the printout and some finer-grained seeds I tried between intervals, the seed interval which triggers "moving the first element to the last" is at least 0.05-0.0=0.05 (same as "doing nothing" for [0.9, 0.95]).
There are two aspects about the behavior which I find troublesome:
1) One-twentieth of the total interval is a large proportion. How are the rest of the shuffle behaviors fairly distributed in the rest of the intervals? (Doesn't "randomness" or "shuffle" conveys "Any order is possible?" How to cram the rest of the randomness in when a large interval is occupied by some behaviors.)
2) "Shift head to tail" & "doing nothing" seem to be very bad/useless behaviors for a shuffling function. Is there something wrong with the implementation?
Please tell me if I made false assumption or logic error. Thank you.
Aucun commentaire:
Enregistrer un commentaire