in reply to Random Derangement Of An Array

All,

Here is an idea I came up with in #perl (freenode) thanks to a few folks there. Assume an even number of elements:

Here is an idea I came up with in #perl (freenode) thanks to a few folks there. Assume an even number of elements:

- 1. Shuffle the indices of the array (copy not actual values)
- 2. Swap adjacent pairs (actually change values)

For instance: 0 - 9 might become 5, 3, 1, 2, 4, 7, 9, 8, 0, 6

Swap index 5 with 3, 1 with 2, 4 with 7, and 9 with 8

Cheers - L~R

In Section
Seekers of Perl Wisdom