RANPERM Function

RANPERM( n ) ;
RANPERM( set, <, numperm> ) ;

The RANPERM function generates random permutations of a set with elements. The random number seed is set by the RANDSEED subroutine.

The first argument, set, can be a scalar or a vector. If set is a scalar, the function returns indices in the range 1–. If set is a vector, the number of elements of the vector determines and the RANPERM function returns elements of set, which can be numeric or character.

By default, the RANPERM function returns a single random combination 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 permutation.

The following statements generate five random permutations of the set :

call randseed(1234);
n = 3; 
p = ranperm(n, 5); 
print p;

Figure 23.251 Random Permutations of Three Items
p
1 2 3
3 2 1
3 2 1
3 1 2
3 1 2

Alternatively, the following statements compute five random permutations of an unsorted character vector:

a = ranperm({C B A}, 5);
print a;

Figure 23.252 Random Permutations of a Character Vector
a
B C A
B A C
C B A
B C A
B C A