in reply to Re: How do I shuffle an array?
in thread How do I shuffle an array?
Let the size of the array be N. Then at each iteration, you select from N elements (after the fix given above), and change it with the one on position $i. You do this N times. Hence, you will get NN different outcomes. There are however, only N! different permutations of the array. And since N! isn't a divisor of NN for N > 2, some outcomes will be favoured over others by your algorithm.
Please use the Fisher-Yates shuffle as described in the FAQ. That one is fair.
Abigail
|
---|