Skip to content

Weighted

getRandomFromWeightedArray<T>(weightedArray, seedOrRNG): T

Defined in: packages/isaacscript-common/src/functions/weighted.ts:19

Get a random value from a WeightedArray. (A WeightedArray is an array of tuples, where the first element in the tuple is a value, and the second element in the tuple is a float corresponding to the value’s weight.)

If you want to get an unseeded element, you must explicitly pass undefined to the seedOrRNG parameter.

T

readonly [T, float][]

The array to pick from.

RNG | Seed | undefined

The Seed or RNG object to use. If an RNG object is provided, the RNG.Next method will be called. If undefined is provided, it will default to a random seed.

T


getRandomIndexFromWeightedArray<T>(weightedArray, seedOrRNG): int

Defined in: packages/isaacscript-common/src/functions/weighted.ts:47

Get a random index from a WeightedArray. (A WeightedArray is an array of tuples, where the first element in the tuple is a value, and the second element in the tuple is a float corresponding to the value’s weight.)

If you want to get an unseeded index, you must explicitly pass undefined to the seedOrRNG parameter.

T

readonly [T, float][]

The array to pick from.

RNG | Seed | undefined

The Seed or RNG object to use. If an RNG object is provided, the RNG.Next method will be called. If undefined is provided, it will default to a random seed.

int