Skip to content

categorical

categorical(options): NumberSampler

Defined in: src/distribution/discrete/bernoulli.ts:77

Categorical: an index in [0, weights.length), proportional to the weights. Uses Vose’s alias method, so each draw is O(1).

CategoricalOptions

NumberSampler

const tier = categorical({ weights: [1, 3, 6] });
tier.sample(); // 2, most of the time