weightedTable
weightedTable<
T>(items,weights):object
Defined in: src/global/collections.ts:233
A reusable weighted sampler, O(1) per draw.
Build one when the same weights are drawn from repeatedly; weightedPick is a linear scan and is the better choice for a one-off.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”Collection<T>
weights
Section titled “weights”ArrayLike<number>
Returns
Section titled “Returns”object
pick()
Section titled “pick()”pick():
T
Returns
Section titled “Returns”T
Example
Section titled “Example”const loot = weightedTable(["common", "rare", "epic"], [90, 9, 1]);loot.pick(); // "common"loot.pick(); // "common"