Weighted
Functions
getRandomFromWeightedArray
▸ getRandomFromWeightedArray<T>(weightedArray, seedOrRNG): T
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
| Name |
|---|
T |
Parameters
| Name | Type | Description |
|---|---|---|
weightedArray | readonly [T, float][] | The array to pick from. |
seedOrRNG | undefined | RNG | Seed | 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
T
Defined in
packages/isaacscript-common/src/functions/weighted.ts:19
getRandomIndexFromWeightedArray
▸ getRandomIndexFromWeightedArray<T>(weightedArray, seedOrRNG): int
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
| Name |
|---|
T |
Parameters
| Name | Type | Description |
|---|---|---|
weightedArray | readonly [T, float][] | The array to pick from. |
seedOrRNG | undefined | RNG | Seed | 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
int