Selects a random value from a weighted set of items.
An array of items with associated weights.
The selected item's value.
If the input array is empty or if weights sum to 0.
const items: WeightedItem[] = [ { value: 1, weight: 5 }, { value: 2, weight: 3 }, { value: 3, weight: 2 },];const result = weightedPick(items); // Randomly picks based on weights Copy
const items: WeightedItem[] = [ { value: 1, weight: 5 }, { value: 2, weight: 3 }, { value: 3, weight: 2 },];const result = weightedPick(items); // Randomly picks based on weights
Selects a random value from a weighted set of items.