BIS fnc selectRandomWeighted: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (example added)
(see also)
Line 41: Line 41:
____________________________________________________________________________________________
____________________________________________________________________________________________


| |= See also
| [[selectRandomWeighted]]|= See also


}}
}}

Revision as of 20:38, 26 June 2017


Hover & click on the images for description

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)
Execution:
call
Groups:
Uncategorised

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:
Return value needed

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

See also:
selectRandomWeighted

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note

Notes

Bottom Section