Arma Reforger Script API
Loading...
Searching...
No Matches
SCR_ArrayHelper Interface Reference

Static Public Member Functions

static int GetWeightedIndex (notnull array< float > weights, float value01)
 Given array of weights, get a random index based on the weight values.
 

Member Function Documentation

◆ GetWeightedIndex()

static int SCR_ArrayHelper.GetWeightedIndex ( notnull array< float > weights,
float value01 )
static

Given array of weights, get a random index based on the weight values.

int index1 = SCR_ArrayHelper.GetWeightedIndex({ 80, 15, 5 }, Math.RandomFloat01());
// index1 has 80% chance of being 0, 15% chance of being 1, 5% chance being 2
int index2 = SCR_ArrayHelper.GetWeightedIndex({ 10, 10, 10, 10 }, Math.RandomFloat01());
// index2 has 25% chance of being 0, 25% chance of being 1, 25% chance of being 2, 25% chance of being 3
Definition SCR_ArrayHelper.c:2
static int GetWeightedIndex(notnull array< float > weights, float value01)
Given array of weights, get a random index based on the weight values.
Definition SCR_ArrayHelper.c:17

i.e in an array [80, 15, 5], 80% of the time, we get index 0, 15% index 1 and 5% index 2, weight sum does not have to add up to any particular value, i.e [100, 100, 100, 100] gives equal 25% distribution (provided random distribution) for all 4 indices

Parameters
[in]weightsarray with weights
[in]valuea value between [0..1], can be random, perlin, or any other; if outside these boundaries, will be Math.Mod-ed
Returns
index selected based on weight or -1 if weights is empty

The documentation for this interface was generated from the following file: