Draws n weighted random samples from an array of objects. Each draw is independent (with replacement), delegating to weighted_rand_select.
n
const opts = [ { value: 'a', probability: 0.9 }, { value: 'b', probability: 0.1 }];weighted_sample_select(3, opts, 'probability');// e.g. [ { value: 'a', ... }, { value: 'a', ... }, { value: 'b', ... } ] Copy
const opts = [ { value: 'a', probability: 0.9 }, { value: 'b', probability: 0.1 }];weighted_sample_select(3, opts, 'probability');// e.g. [ { value: 'a', ... }, { value: 'a', ... }, { value: 'b', ... } ]
Number of samples to draw.
Non-empty array of weighted objects.
Name of the numeric weight property.
Optional
Optional random number generator.
An array of n independently selected items.
Draws
nweighted random samples from an array of objects. Each draw is independent (with replacement), delegating to weighted_rand_select.