Shuffle

bearophile bearophileHUGS at lycos.com
Fri Jan 25 03:54:59 PST 2008


Oskar Linde:
> To be nitpicky, your algorithm will not give a perfect shuffling. 
> Consider shuffling the sequence 012. The algorithm has 3^3 = 27 
> different ways it can shuffle the sequence, and there exists 3! = 6 
> different permutations of the sequence. Since 27 isn't divisible by 6, 
> the algorithm will give a slight bias towards some end sequences.

Thank you Oskar for showing why a shuffle() function is necessary in std.random, among other things. You can find one in my d libs, based on Knuth simple algorithm ;-)

Bye,
bearophile


More information about the Digitalmars-d-announce mailing list