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.
Parameters
Section titled “Parameters”any[]
input array. can contain any type
number
count of how many elements to take
randomSource?
Section titled “randomSource?”Function
an optional entropy source that returns numbers between 0 inclusive and 1 exclusive: the range [0, 1)
Returns
Section titled “Returns”any[]
subset of n elements in original array
Example
Section titled “Example”var values = [1, 2, 4, 5, 6, 7, 8, 9];sample(values, 3); // returns 3 random values, like [2, 5, 8];