for (const value of new RandomSampling({ candidates: [1, 2, 3], sampleSize: 5, replace: true,})) { console.log(value);} Copy
for (const value of new RandomSampling({ candidates: [1, 2, 3], sampleSize: 5, replace: true,})) { console.log(value);}
for (const value of new RandomSampling({ candidates: [1, 2, 3], sampleSize: 2, replace: false,})) { console.log(value);} Copy
for (const value of new RandomSampling({ candidates: [1, 2, 3], sampleSize: 2, replace: false,})) { console.log(value);}
Something to be sampled
Optional
Number of generated samples
candidates.length Copy
candidates.length
With or without replacement
true Copy
true
Calculate the next value
Next value or undefined if the iterator is done
undefined
Example: With replace
Example: Without replace