Skip to content

sample

sample(x, n, randomSource?): any[]

Defined in: src/sample.js:20

Create a simple random sample from a given array of n elements.

The sampled values will be in any order, not necessarily the order they appear in the input.

any[]

input array. can contain any type

number

count of how many elements to take

Function

an optional entropy source that returns numbers between 0 inclusive and 1 exclusive: the range [0, 1)

any[]

subset of n elements in original array

var values = [1, 2, 4, 5, 6, 7, 8, 9];
sample(values, 3); // returns 3 random values, like [2, 5, 8];