Arma 3 Scripting

Function in Arrays

BIS_fnc_selectRandomWeighted

Also available as Markdown and JSON, or read the original wiki page.

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:

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;

See also

selectRandomWeighted