next up previous contents
Next: Scrambling Strings Up: Randomization Previous: Random Seeding

Random Permutations

A permutation of a set P is an ordered sequence of all the elements of P, with each element appearing exactly once. For example,there are six permutations of the set $P=\{1,2,3\}$
<1, 2, 3>, <1, 3, 2>, <2, 1, 3>, <2, 3, 1>, <3, 1, 2>, <3, 2, 1>
The CreateRandPermutation functions creates a random permutation of the set $P_{n}=\{1, 2, \ldots, n\}$.

> CreateRandPermutation(5);
[1, 2, 4, 3, 5]
> CreateRandPermutation(5);
[5, 2, 3, 4, 1]

Note that CreateRandPermutation uses the same predefined seed as the function Rand. Issuing either SetRand or SetRandSeed changes the sequence.



Gaston Gonnet
1998-09-15