Knuth shuffle: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
No edit summary |
||
Line 2,169: | Line 2,169: | ||
res.toList()</syntaxhighlight> |
res.toList()</syntaxhighlight> |
||
=={{header|FutureBasic}}== |
|||
<syntaxhighlight lang="futurebasic"> |
|||
include "NSLog.incl" |
|||
void local fn KnuthShuffle( mutArr as CFMutableArrayRef ) |
|||
NSUInteger i, j, count |
|||
count = len(mutArr) |
|||
for i = 0 to count -1 |
|||
j = rnd( i + 1 ) |
|||
MutableArrayExchangeObjects( mutArr, i, j ) |
|||
next |
|||
end fn |
|||
randomize |
|||
CFMutableArrayRef mutArr |
|||
NSUInteger i |
|||
mutArr = fn MutableArrayWithObjects( @0, @1, @2, @3, @4, @5, @6, @7, @8, @9 ) |
|||
NSLog( @"Before shuffle: %@", fn ArrayComponentsJoinedByString( mutArr, @"" ) ) |
|||
fn KnuthShuffle( mutArr ) |
|||
NSLog( @"After shuffle: %@", fn ArrayComponentsJoinedByString( mutArr, @"" ) ) |
|||
fn KnuthShuffle( mutArr ) |
|||
NSLog( @"After shuffle: %@", fn ArrayComponentsJoinedByString( mutArr, @"" ) ) |
|||
HandleEvents |
|||
</syntaxhighlight> |
|||
((output}} |
|||
<pre> |
|||
Before shuffle: 0123456789 |
|||
After shuffle: 1650439827 |
|||
After shuffle: 6702185439 |
|||
</pre> |
|||
=={{header|Gambas}}== |
=={{header|Gambas}}== |