Talk:Shuffle an array

From CodeCodex

In the fisher-yates function, it appears that 'swap' is assigned incorrectly. Presently, the line is as follows:

swap+=($array[k])

Rather than replacing the value of swap, this syntax appends array[k] to whatever 'swap' has at the time. This causes 'swap' to grow in size with each loop iteration. When an element of the original array is replaced, multiple values are inserted. As a result, the output array is larger (by a lot) than the input array. I'm pretty sure this can be fixed by removing the '+' as in:

swap=($array[k]}

I currently use this modification under ZSH version 4.2.6 without issue.