BIS fnc selectRandomWeighted: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (1 revision)
m (example added)
Line 28: Line 28:
____________________________________________________________________________________________
____________________________________________________________________________________________


| <!-- [] call [[BIS_fnc_selectRandomWeighted]]; --> |= Syntax
| [array1, array2] call BIS_fnc_selectRandomWeighted; |= Syntax


|p1= |= Parameter 1
|p1=array1: [[Array]] - selectable values |= Parameter 1
|p2=array2: [[Array]] of [[Number]]s - values weight: first weight is for array1 first element, etc. |= Parameter 1


| |= Return value
| |= Return value
____________________________________________________________________________________________
____________________________________________________________________________________________


|x1= <code></code> |=  
|x1= <code>_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</code> |=  
____________________________________________________________________________________________
____________________________________________________________________________________________



Revision as of 18:07, 24 July 2016


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:
See also needed

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