RANCOMB
(n, k <, numcomb> ) ;
RANCOMB
(set, k <, numcomb> ) ;
The RANCOMB function generates random combinations of k elements taken from a set of 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 RANCOMB function returns elements of set.
By default, the RANCOMB function returns a single random combination with one row and columns. If the numcomb argument is specified, the function returns a matrix with numcomb rows and k columns. Each row of the returned matrix represents a single combination.
The following statements generate five random combinations of two elements from the set :
n = 4; k = 2; call randseed(1234); c = rancomb(n, k, 5); print c;
Figure 23.258: Random Pairwise Combinations of Four Items
c | |
---|---|
1 | 4 |
1 | 2 |
2 | 4 |
2 | 3 |
1 | 3 |
The function can return combinations for arbitrary numerical or character matrices. For example, the following statements generate five random pairwise combinations of four elements:
d = rancomb({A B C D}, 2, 5); print d;
Figure 23.259: Random Pairwise Combinations of Four Characters
d | |
---|---|
A | D |
A | B |
A | D |
B | D |
A | B |