UNPKG

weighted-pick

Version:

A library to pick random elements with weighted probability.

11 lines (9 loc) 211 B
export type WeightedValue<T> = Readonly<{ value: T; weight: number; }> export class WeightedPick<T> { constructor(weights: WeightedValue<T>[]); pickValue(): T; pickValues(n: number): T[]; }