RANPERK
(n, k <, numperm> ) ;
RANPERK
(set, k <, numperm> ) ;
The RANPERK function generates a random permutation of k elements from a set of elements. The random number seed is set by the RANDSEED subroutine. The RANPERK function is similar to the RANCOMB function. A combination is a sorted permutation of the k elements.
The first argument, set, can be a scalar or a vector. If set is a scalar, the function returns k indices in the range 1–. If set is a vector, the number of elements of the vector determines , and the RANPERK function returns k elements of set, which can be numeric or character.
By default, the RANPERK function returns a single random permutation with one row and columns. If the numperm argument is specified, the function returns a matrix with numperm rows and columns. Each row of the returned matrix represents a single random draw.
The following statements generate four random permutations that consist of two elements from the set 1, 2, 3:
call randseed(1234); n = 3; p = ranperk(n, 2, 4); print p;
Figure 23.262: Two Elements of a Random Permutation
p | |
---|---|
3 | 1 |
1 | 2 |
3 | 2 |
1 | 3 |
Alternatively, the following statements compute random permutations that consist of two elements from an unsorted character vector:
q = ranperk({C B A}, 2, 4); print q;
Figure 23.263: Random Permutation of a Character Vector
q | |
---|---|
C | A |
C | A |
B | C |
A | C |