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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Random Derangement Of An Array (rotate)
by tye (Sage) on Jul 05, 2008 at 22:11 UTC | |
by Limbic~Region (Chancellor) on Jul 05, 2008 at 22:56 UTC | |
by moritz (Cardinal) on Jul 09, 2008 at 18:36 UTC | |
by Limbic~Region (Chancellor) on Jul 09, 2008 at 21:58 UTC |
In Section
Seekers of Perl Wisdom