BIS fnc selectRandomWeighted: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) m (Text replacement - " \[\[Category:\{\{Name|[a-z0-9]+\}\}: Functions\|\{\{uc:[a-zA-Z0-9]+\}\}\]\]" to "") |
Lou Montana (talk | contribs) m (Some wiki formatting) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 15: | Line 15: | ||
|gr1= Arrays | |gr1= Arrays | ||
|descr= Selects a random item from an array, taking into account item weight. | |descr= Selects a random item from an array, taking into account item weight. | ||
* The weights | {{Feature|informative| | ||
* 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 | * The length of weights and items arrays may not match, in which case the shortest array is used for length | ||
}} | |||
{{Feature|arma3|See [[selectRandomWeighted]] for an engine solution.}} | {{Feature|arma3|See [[selectRandomWeighted]] for an engine solution.}} | ||
|s1= | |s1= itemsAndWeights call [[BIS_fnc_selectRandomWeighted]] | ||
|p1=itemsAndWeights: [[Array]] - array of items and weights [item, weight, item, weight...] | |p1= itemsAndWeights: [[Array]] - array of items and weights [item, weight, item, weight...] | ||
|r1= [[Anything]] | |r1= [[Anything]] | ||
|s2= [items, weights] call [[BIS_fnc_selectRandomWeighted]] | |s2= [items, weights] call [[BIS_fnc_selectRandomWeighted]] | ||
| | |p21= items: [[Array]] - items array of [[Anything]] | ||
| | |p22= weights: [[Array]] - weights array of [[Number]]s | ||
|r2= [[Anything]] | |r2= [[Anything]] | ||
| | |x1= <sqf>["apples",.3,"pears",.2,"bananas",.4,"diamonds",.1,"unicorns",.00001] call BIS_fnc_selectRandomWeighted;</sqf> | ||
|x2= <sqf>[["apples","pears","bananas","diamonds"], [0.3,0.2,0.4,0.1]] call BIS_fnc_selectRandomWeighted;</sqf> | |||
|seealso= [[selectRandomWeighted]] | |seealso= [[selectRandomWeighted]] | ||
}} | }} | ||
Latest revision as of 16:41, 13 July 2022
Description
- Description:
- Selects a random item from an array, taking into account item weight.
- Execution:
- call
- Groups:
- Arrays
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: 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:
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