in reply to Shuffle an array

If you search for "shuffle" on CPAN, you'll find Shuffle.pm by Abigail, which implements the Fisher-Yates algorithm everyone keeps mentioning. If you want to see how it really works, take a look at the code in that module.

The basic idea is, looking at each slot in the array, from the last to the first, swap it with one other before it in the array, chosen at random. That is, if you have an array of length 6, swap $a[5] (the last element) with one chosen at random from @a[0..4], then swap $a[4] with one from @a[0..3], and so on down. Obviously, when you get to $a[1], you can stop.

This is a very effective shuffling technique (assuming you've got a good random number generator). For a good explanation of why, you can read the documentation for Abigail's module.

jdporter
...porque es dificil estar guapo y blanco.