Order Bias In Wrong Implementation Of Fisher Yates Shuffle
I implemented the shuffling algorithm as: import random a = range(1, n+1) #a containing element from 1 to n for i in range(n): j = random.randint(0, n-1) a[i], a[j] = a[j],
Solution 1:
This is not a proof by any means, but you can quickly come up with the distribution of placement probabilities by running the biased algorithm a million times. It will look like this picture from wikipedia:
An unbiased distribution would have 14.3% in every field.
To get the most likely distribution, I think it's safe to just pick the highest percentage for each index. This means it's most likely that the entire array is moved down by one and the first element will become the last.
Edit: I ran some simulations and this result is most likely wrong. I'll leave this answer up until I can come up with something better.
Post a Comment for "Order Bias In Wrong Implementation Of Fisher Yates Shuffle"