Skip to content

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.

T

Collection<T>

ArrayLike<number>

object

pick(): T

T

const loot = weightedTable(["common", "rare", "epic"], [90, 9, 1]);
loot.pick(); // "common"
loot.pick(); // "common"