Assuming that shuffling is simple is a mistake, and yet once you see an unbiased algorithm on paper (or screen) you will probably say, "Oooh, I get it." But done wrong, shuffling can introduce bias, and it's easy to do wrong.
There is a nice article on Wikipedia: Fisher-Yates Shuffle. Implemented as a computer algorithm, it is sometimes known as the Knuth Shuffle. Also looking at the Pure Perl version of List::Util (here: Source for List::Util::PP) you will see a Perlish implementation of Fisher-Yates.
Another post here pointed you to perlfaq4, which shows another Fisher-Yates implementation that is easier to read than the List::Util::PP version.
For the masochistic or exceptionally curious: The Art of Computer Programming vol. 2 (3rd ed.), pg 145-146.
Dave
In reply to Re^3: array shuffle
by davido
in thread array shuffle
by boom.roasted
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |