Weighted
Functions
Section titled “Functions”getRandomFromWeightedArray()
Section titled “getRandomFromWeightedArray()”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.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”weightedArray
Section titled “weightedArray”readonly [T, float][]
The array to pick from.
seedOrRNG
Section titled “seedOrRNG”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.
Returns
Section titled “Returns”T
getRandomIndexFromWeightedArray()
Section titled “getRandomIndexFromWeightedArray()”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.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”weightedArray
Section titled “weightedArray”readonly [T, float][]
The array to pick from.
seedOrRNG
Section titled “seedOrRNG”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.
Returns
Section titled “Returns”int
