BIS fnc selectRandomWeighted: Difference between revisions
Jump to navigation
Jump to search
Killzone Kid (talk | contribs) (docs updated) |
m (template:command argument fix) |
||
Line 10: | Line 10: | ||
| Selects a random item from an array, taking into account item weight. Note: | | Selects a random item from an array, taking into account item weight. Note: | ||
* The weights don't have to total to 1 | * The weights don't 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|= | * The length of weights and items arrays may not match, in which case the shortest array is used for length|DESCRIPTION= | ||
____________________________________________________________________________________________ | ____________________________________________________________________________________________ | ||
| itemsAndWeights call [[BIS_fnc_selectRandomWeighted]] |= | | itemsAndWeights call [[BIS_fnc_selectRandomWeighted]] |SYNTAX= | ||
|p1=itemsAndWeights: [[Array]] - array of items and weights [item, weight, item, weight...]|= | |p1=itemsAndWeights: [[Array]] - array of items and weights [item, weight, item, weight...]|PARAMETER1= | ||
| [[Anything]] |= | | [[Anything]] |RETURNVALUE= | ||
|s2= [items, weights] call [[BIS_fnc_selectRandomWeighted]] |= | |s2= [items, weights] call [[BIS_fnc_selectRandomWeighted]] |SYNTAX= | ||
|p21=[items, weights]: [[Array]]|= | |p21=[items, weights]: [[Array]]|PARAMETER1= | ||
|p22=items: [[Array]] - items array of [[Anything]] |= | |p22=items: [[Array]] - items array of [[Anything]] |PARAMETER1= | ||
|p23=weights: [[Array]] - weights array of [[Number]]s |= | |p23=weights: [[Array]] - weights array of [[Number]]s |PARAMETER1= | ||
|r2= [[Anything]] |= | |r2= [[Anything]] |RETURNVALUE= | ||
____________________________________________________________________________________________ | ____________________________________________________________________________________________ | ||
|x1= <code>["apples",.3,"pears",.2,"bananas",.4,"diamonds",.1,"unicorns",.00001] [[call]] [[BIS_fnc_selectRandomWeighted]];</code> |= | |x1= <code>["apples",.3,"pears",.2,"bananas",.4,"diamonds",.1,"unicorns",.00001] [[call]] [[BIS_fnc_selectRandomWeighted]];</code> |= | ||
Line 30: | Line 30: | ||
____________________________________________________________________________________________ | ____________________________________________________________________________________________ | ||
| [[selectRandomWeighted]]|= | | [[selectRandomWeighted]]|SEEALSO= | ||
}} | }} |
Revision as of 14:33, 7 April 2019
Description
- Description:
- Selects a random item from an array, taking into account item weight. Note:
- The weights don't 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
- Execution:
- call
- Groups:
- Uncategorised
Syntax
- Syntax:
- itemsAndWeights call BIS_fnc_selectRandomWeighted
- Parameters:
- itemsAndWeights: Array - array of items and weights [item, weight, item, weight...]
- Return Value:
- Anything
Alternative Syntax
- Syntax:
- [items, weights] call BIS_fnc_selectRandomWeighted
- Parameters:
- [items, weights]: Array
- items: Array - items array of Anything
- weights: Array - weights array of Numbers
- Return Value:
- 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;
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