Shuffle

BCS BCS at pathlink.com
Fri Jan 25 10:43:38 PST 2008


Oskar Linde wrote:
> Walter Bright wrote:
> 
>>     /* Shuffle the files[] array
>>      */
> 
> 
> 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. 
> (021,102 and 120 in this case). A quick fix is to change the first line 
> of the loop body:
> 

What would you get if you qsorted the list with rand used as the compare 
function?


More information about the Digitalmars-d-announce mailing list