Randomly select K samples from a population N.
RANDOMIZE(n, k, replace)
n |
- |
An integer or array, the input population. If n is an integer, the population is the series 1..n. |
||||
k |
- |
Optional. An integer, the number of samples to randomly select from population n. Defaults to length(n). |
||||
replace |
- |
Optional. An integer, the replacement flag.
|
A series or array, the randomly selected samples.
W1: randsample(1..5)
W2: randsample(5)
W1 randomly resamples the series {1, 2, 3, 4, 5}.
W2 performs the same. The results are not identical because different samples are randomly selected.
W3: seedrand(100);randsample(1..5)
W4: seedrand(100);randsample(5)
Same as above except the random number generator is set to the same seed value in both random selections, resulting in W3 == W4.
W1: 11..20
W2: randsample(w1, 8, 0)
W3: randsample(w1, 8, 1)
W1 contains the series 11..20.
W2 randomly selects 8 values from W1 without replacement. The 8 resulting values are unique and fall in the range between 11 and 20.
W3 randomly selects 8 values from W1 with replacement. The 8 resulting values fall in the range between 11 and 20 and some of the values may be repeated.
W1: gnorm(10, 1);
W2: randsample(w1, 8, 0)
W3: randsample(w1, 8, 1)
Same as above except the source array in W1 consists of 10 normally distributed random values.
W2 contains always contains unique values whereas W3 could contain repeated values.
W2 randomly selects 8 values from W1 without replacement. The 8 resulting values are unique and fall in the range between 11 and 20.
RANDSAMPLE randomly selects k samples from a population n.
The population is set to 1..n if n is a scalar.
The replace flag must be 1 if k, the number of selections is greater than the population size specified by n.