Description
Selects a random item from an array, taking into account item weight.
Note
- The weights do not have to total to 1
- The length of weights and items arrays may not match, in which case the shortest array is used for length
Note
Arma 3: See selectRandomWeighted for an engine solution.
Syntax
Syntax 1
itemsAndWeights call BIS_fnc_selectRandomWeighted
Parameters:
itemsAndWeights: Array - array of items and weights [item, weight, item, weight...]
Returns: Anything
Syntax 2
[items, weights] call BIS_fnc_selectRandomWeighted
Parameters:
Returns: Anything
Examples
Example 1
["apples",.3,"pears",.2,"bananas",.4,"diamonds",.1,"unicorns",.00001] call BIS_fnc_selectRandomWeighted;
Example 2
[["apples","pears","bananas","diamonds"], [0.3,0.2,0.4,0.1]] call BIS_fnc_selectRandomWeighted;