Permutation: Permute randomly...

Generates a new Permutation by randomly permuting a range of elements in the selected Permutation object.

Setting

Index range
defines the range of elements that will be permuted. The elements outside this range will be kept intact.

Example

If we start with the permutation (4,6,3,1,5,2,7) and a chosen Index range that runs from 3 to 6, a new permutation will be generated as follows:

1. A new permutation of the same dimension as the selected one will be created.
2. Because the index range starts at 3, the first two elements of the selected permutation will be copied to the first two locations in the newly created permutation. The new permutation is now (4,6,.,.,.,.,.), where a dot (.) means that the element is unspecified.
3. The elements 3 to 6 of the selected permutation, i.e. the numbers (3,1,5,2) will be randomly permuted. There are 24 possible permutations of these 4 numbers. Say the outcome happens to be (5,1,3,2). The new permutation is now (4,6,5,1,3,2,.).
4. The remaining element (7) is copied to the new permutation. Finally, this results in the new permutation being (4,6,5,1,3,2,7).

© djmw, November 23, 2011