Shuffle

Lars Ivar Igesund larsivar at igesund.net
Fri Jan 25 04:15:08 PST 2008


bearophile wrote:

> 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

FWIW, tango.core.Array gained shuffle last night :)

-- 
Lars Ivar Igesund
blog at http://larsivi.net
DSource, #d.tango & #D: larsivi
Dancing the Tango


More information about the Digitalmars-d-announce mailing list