4 ms·
I've used that method too. The flaw is that it is biased; some permutations will be more likely than others. Each shuffle will consume N random numbers between
by paulgb 17y ago
I've used that method too. The flaw is that it is biased; some permutations will be more likely than others.
Each shuffle will consume N random numbers between 1 and N (inclusive). This gives a total of N^N equally probable N-tuples of random numbers, all corresponding to exactly one output permutation.
But there are only N! possible permutations, so some of the N^N N-tuples must share the same output permutation. Since N! does not usually divide N^N evenly, some permutations must be more probable than others.
- Aron 17y agoAh....clever. thx.