Skip to content

sampleIndices(random, populationSize, sampleSize): readonly number[]

Defined in: packages/sampling/src/sample-indices.ts:17

Sample a uniform subset of 0..populationSize - 1 in ascending order.

Floyd’s algorithm uses O(sampleSize) expected auxiliary space, followed by an O(sampleSize log sampleSize) canonical sort. The inputs are not mutated.

RandomSource

number

number

readonly number[]

With code INVALID_POPULATION_SIZE when populationSize is not a safe integer in 0..2^32, or INVALID_SAMPLE_SIZE when sampleSize is not representable or exceeds the population.

With code INVALID_SOURCE_VALUE when the random source returns a value outside [0, 1).