MCPcopy Create free account
hub / github.com/breck7/scroll / sampleWithoutReplacement

Method sampleWithoutReplacement

external/.scrollLibs.js:14454–14467  ·  view source on GitHub ↗
(population = [], quantity, seed)

Source from the content-addressed store, hash-verified

14452 }
14453 }
14454 static sampleWithoutReplacement(population = [], quantity, seed) {
14455 const prng = this._getPseudoRandom0to1FloatGenerator(seed)
14456 const sampled = {}
14457 const populationSize = population.length
14458 if (quantity >= populationSize) return population.slice(0)
14459 const picked = []
14460 while (picked.length < quantity) {
14461 const index = Math.floor(prng() * populationSize)
14462 if (sampled[index]) continue
14463 sampled[index] = true
14464 picked.push(population[index])
14465 }
14466 return picked
14467 }
14468 static arrayToMap(arr) {
14469 const map = {}
14470 arr.forEach(val => (map[val] = true))

Callers

nothing calls this directly

Calls 2

sliceMethod · 0.80

Tested by

no test coverage detected