--$i is calculated before entering the body. And rand($i + 1) will never return the value of $i.
The loop control that works is:
for ( my $i = @$array; $i; $i-- ) {
This was originally posted as an Answer to the Categorized Question How do I shuffle an array?. It was removed from the CatQA section because it is not a good answer.
In reply to How do I shuffle an array? by BramVanOosterhout
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |