weightedPick
weightedPick<
T>(items,weights):T
Defined in: src/global/collections.ts:197
One element, with probability proportional to its weight.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”Collection<T>
weights
Section titled “weights”ArrayLike<number>
Returns
Section titled “Returns”T
Example
Section titled “Example”// "common" ten times as often as "rare".weightedPick(["common", "rare"], [10, 1]); // "common"