Skip to contents

This function provides a very efficient way to pull an integer random sample sequence from an integer interval.

Usage

sample_seq(low, high, length)

Arguments

low

The lower limit of the interval (inclusive).

high

The higher limit of the interval (inclusive).

length

The length of the sample.

Value

An increasing numeric vector containing integers, the sample.

Details

The algorithm runs in O(length) expected time, even if high-low is big. It is much faster (but of course less general) than the builtin sample function of R.

random_sample

References

Jeffrey Scott Vitter: An Efficient Algorithm for Sequential Random Sampling, ACM Transactions on Mathematical Software, 13/1, 58–67.

See also

Author

Gabor Csardi csardi.gabor@gmail.com

Examples


rs <- sample_seq(1, 100000000, 10)
rs
#>  [1]  2993803 10864525 34917854 47368824 61268521 66100154 72719076 82951174
#>  [9] 83574691 94011550