note
BlaisePascal
How random do you want it, and what do you mean by "randomize"? I assume you want a random permutation, all permutations equally likey.
<p>
The traditional solution is something like:
<code>
for $i ($#array..0) {
my $j = rand($i);
@array[$i,$j] = @array[$j,$i];
}
</code>
This does @array swaps, and can be shown (see Knuth) that all permutations are equally likely -- assuming I haven't made any coding mistakes
<p>
This is probably the fastest randomization algorithm, although various implementations might be faster than mine.
31461
31461