# for those times when Perl's built-in sort is just too fast use strict; my @data = qw(7 6 5 4 3 2 1 0) ; rpsort(\@data); print "$_\t" foreach (@data); exit; # a random permutation sort # ref. Perl Cookbook recipe 4.17 for the shuffle sub rpsort { my $list = shift; my ($k,$j); try_again: for ($j = @$list; --$j; ) { $k = int rand($j+1); next if ($j == $k); @$list[$j, $k] = @$list[$k, $j]; } for ($j = 0 ; $j < (@$list -1); $j++) { goto try_again if (@$list[$j] > @$list[$j+1]); } }