BIS_fnc_selectRandomWeighted

From Bohemia Interactive Community
Jump to: navigation, search
Introduced with Arma 2 version 1.00
  

Click on the images for descriptions

Introduced in

Game:
Arma 2
Version:
1.00

Description

Description:
/*

	Description:
	Function to select a random item from an array, taking into account item weights.
	The weights should be Numbers between 0 and 1, with a maximum precision of hundreds.
	
	Parameter(s):
	_this select 0: source Array (Array of Any Value)
	_this select 1: weights (Array of Number)
	
	Returns:
	Any Value selected item
	
	TODO:
	[*] Algorithm is inefficient?
*/

(Placeholder description extracted from the function header by BIS_fnc_exportFunctionsToWiki)

Syntax

Syntax:
[array1, array2] call BIS_fnc_selectRandomWeighted;
Parameters:
array1: Array - selectable values
array2: Array of Numbers - values weight: first weight is for array1 first element, etc.
Return Value:

Examples

Example 1:
_choices = ["cat", "dog"]; _weights = [0.5, 1.0]; [_choices, _weights] call BIS_fnc_selectRandomWeighted]; // will result in 2/3 of dogs, 1/3 of cats

Additional Information

Execution:
call
Multiplayer:
-
See also:
See also needed

Notes

Only post proven facts here. Report bugs on the feedback tracker. Use the talk page or the forums for discussions.
Add New Note | How To

Notes

Bottom Section