in reply to Is this a fair shuffle?
It looks basically OK for most purposes (although if I were using it for security purposes I'd use one of the published and widely recognized shuffling algorithms).
Here's a oneliner that does the equivalent thing inplace. It walks through the array, and for the current element randomly picks one of the remaining elements and swaps it with the current element. It's not actually shorter than yours, so I'm not sure there's much use for it.
for (0..$#a) { my $r = rand(@a)-$_; @a[$_,$r]=@a[$r,$_]; };
|
|---|