Take a random sample from a sequence
Common Lisp
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
tests
.gitignore
README.md
package.lisp
random-sample.asd
random-sample.lisp
readtable.lisp

README.md

Random-Sample is a Lisp library for something which is not nearly as simple as it sounds: reliably taking a random sample of a sequence.

Most of the time you will just use random-sample:

(random-sample:random-sample (iota 100) 5)
=> (57 32 28 45 4)

The algorithm used for sampling without replacement is basically Vitter’s Algorithm D.

Sometimes you may want to use the algorithm at a lower level. You don’t want the sample itself; you only want the indices. In this case, you can directly use map-random-below, which simply calls a provided function on each index.

(map-random-below my-function 5 length)