Knuth shuffle: Difference between revisions
Content added Content deleted
Line 2,177: | Line 2,177: | ||
void local fn KnuthShuffle( mutArr as CFMutableArrayRef ) |
void local fn KnuthShuffle( mutArr as CFMutableArrayRef ) |
||
NSUInteger i, j, count |
NSUInteger i, j, count |
||
count = len(mutArr) |
count = len(mutArr) |
||
for i = 0 to count -1 |
for i = 0 to count -1 |
||
cln j = arc4random_uniform(i); |
|||
j = rnd( i + 1 ) |
|||
⚫ | |||
if j > count - 1 then j = count - 1 |
|||
⚫ | |||
⚫ | |||
⚫ | |||
end fn |
end fn |
||
Line 2,194: | Line 2,193: | ||
NSLog( @"Before shuffle: %@", fn ArrayComponentsJoinedByString( mutArr, @"" ) ) |
NSLog( @"Before shuffle: %@", fn ArrayComponentsJoinedByString( mutArr, @"" ) ) |
||
for i = 1 to |
for i = 1 to 100 |
||
fn KnuthShuffle( mutArr ) |
fn KnuthShuffle( mutArr ) |
||
NSLog( @"%@", fn ArrayComponentsJoinedByString( mutArr, @"" ) ) |
NSLog( @"%@", fn ArrayComponentsJoinedByString( mutArr, @"" ) ) |
||
next |
next |
||