3 ms·
Besides the performance difference, the main issue is the ideal of a perfect shuffle: each of the N! sorts ought to be equally likely. (N.b.: this post ended u
by crux_ 17y ago
Besides the performance difference, the main issue is the ideal of a perfect shuffle: each of the N! sorts ought to be equally likely.
(N.b.: this post ended up being mostly the same point as fhars, only phrased differently.)
However, this is tricky to achieve. It requires either:
- an infinite source of random numbers
- a psuedo random number generator whose pool size (the # of random numbers it can generate) is an even multiple of N! (If not, then it have bias towards certain shuffles almost by definition.)
Here's what happens when someone does it all wrong -- the wrong shuffle algorithm and, far more devastatingly, a poor PRNG choice:
http://www.cigital.com/papers/download/developer_gambling.php http://www.cigital.com/papers/download/developer_gambling.ph...
(Consider that if your PRNG takes a 32-bit seed, there will be at most be 2^32 possible shuffles, even with a correctly perfect shuffling algorithm --- few enough for an attacker to pre-calculate every possible shuffle to use against you.)