Knuth shuffle: Difference between revisions

m
Line 2,182:
for i = 0 to count -1
j = rnd( i + 1 )
if j > count - 1 then j = count - 1
MutableArrayExchangeObjects( mutArr, i, j )
next
Line 2,189 ⟶ 2,190:
 
CFMutableArrayRef mutArr
NSUInteger i
mutArr = fn MutableArrayWithArrayMutableArrayWithObjects( @[@0, @1, @2, @3, @4, @5, @6, @7, @8, @9] )
NSLog( @"Before shuffle: %@", fn ArrayComponentsJoinedByString( mutArr, @"" ) )
 
for i = 1 to 10
fn KnuthShuffle( mutArr )
NSLog( @"After shuffle: %@", fn ArrayComponentsJoinedByString( mutArr, @"" ) )
next
fn KnuthShuffle( mutArr )
NSLog( @"After shuffle: %@", fn ArrayComponentsJoinedByString( mutArr, @"" ) )
 
HandleEvents
</syntaxhighlight>
{{outoutput}}
<pre>
Before shuffle: 0123456789
1274860395
After shuffle: 1650439827
2715638904
After shuffle: 6702185439
7182035964
1297658403
2916574083
9162507843
1875962034
8721965034
7968402351
9347510862
</pre>
 
715

edits