ReferenceSamplersFunction
pick()
Picks one of several values at random.
function pick<T>(arr: T[], weights?: number[]): SamplerFn<T>;Creates a sampler that picks one of the given values at random, either with equal chances or weighted ones.
Weights are relative and don’t need to add up to 1: [3, 1] will make the first value three times as likely
as the second one.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”arrT[]The values to pick from.
weightsoptionalnumber[]Optional relative chances, one per value.
Returns
Section titled “Returns”SamplerFn<T>
Throws
Section titled “Throws”- PartyJSError
If
arris empty, if the number of weights doesn’t match the number of values, if a weight is negative or if all weights are zero.
Example
Section titled “Example”// Mostly circles with an occasional star.pick([{ type: "circle" }, { type: "star" }], [4, 1]);