Skip to content

sampleWithReplacement

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

Defined in: src/sample_with_replacement.js:14

Sampling with replacement is a type of sampling that allows the same item to be picked out of a population more than once.

any[]

an array of any kind of value

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[]

n sampled items from the population

var values = [1, 2, 3, 4];
sampleWithReplacement(values, 2); // returns 2 random values, like [2, 4];