BIS fnc selectRandomWeighted: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "{{Feature arma3|" to "{{Feature|arma3|")
m (Some wiki formatting)
 
(20 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Function|Comments=
{{RV|type=function
____________________________________________________________________________________________


| arma2 |Game name=
|game1= arma2
|version1= 1.00


|1.00|Game version=
|game2= arma2oa
|version2= 1.50


|gr1= Arrays |GROUP1=
|game3= tkoh
____________________________________________________________________________________________
|version3= 1.00


| Selects a random item from an array, taking into account item weight. Note:
|game4= arma3
* The weights don't have to total to 1
|version4= 0.50
 
|gr1= Arrays
 
|descr= Selects a random item from an array, taking into account item weight.
{{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.}} |DESCRIPTION=
{{Feature|arma3|See [[selectRandomWeighted]] for an engine solution.}}
____________________________________________________________________________________________
 
| itemsAndWeights call [[BIS_fnc_selectRandomWeighted]] |SYNTAX=


|p1=itemsAndWeights: [[Array]] - array of items and weights [item, weight, item, weight...] |PARAMETER1=
|s1= itemsAndWeights call [[BIS_fnc_selectRandomWeighted]]


| [[Anything]] |RETURNVALUE=
|p1= itemsAndWeights: [[Array]] - array of items and weights [item, weight, item, weight...]


|s2= [items, weights] call [[BIS_fnc_selectRandomWeighted]] |SYNTAX2=
|r1= [[Anything]]


|p21=[items, weights]: [[Array]]|PARAMETER21=
|s2= [items, weights] call [[BIS_fnc_selectRandomWeighted]]
|p22=items: [[Array]] - items array of [[Anything]] |PARAMETER22=
|p21= items: [[Array]] - items array of [[Anything]]


|p23=weights: [[Array]] - weights array of [[Number]]s |PARAMETER23=
|p22= weights: [[Array]] - weights array of [[Number]]s


|r2= [[Anything]] |RETURNVALUE2=
|r2= [[Anything]]
____________________________________________________________________________________________
|x1= <code>["apples",.3,"pears",.2,"bananas",.4,"diamonds",.1,"unicorns",.00001] [[call]] [[BIS_fnc_selectRandomWeighted]];</code> |Example1=


|x2= <code><nowiki>[</nowiki>["apples","pears","bananas","diamonds"],[0.3,0.2,0.4,0.1]] [[call]] [[BIS_fnc_selectRandomWeighted]];</code> |=
|x1= <sqf>["apples",.3,"pears",.2,"bananas",.4,"diamonds",.1,"unicorns",.00001] call BIS_fnc_selectRandomWeighted;</sqf>
____________________________________________________________________________________________


| [[selectRandomWeighted]]|SEEALSO=
|x2= <sqf>[["apples","pears","bananas","diamonds"], [0.3,0.2,0.4,0.1]] call BIS_fnc_selectRandomWeighted;</sqf>


|seealso= [[selectRandomWeighted]]
}}
}}
<h3 style="display:none">Notes</h3>
<dl class="command_description">
<!-- Note Section BEGIN -->
<!-- Note Section END -->
</dl>
<h3 style="display:none">Bottom Section</h3>
[[Category:{{Name|arma2oa}}: Functions|{{uc:selectRandomWeighted}}]]
[[Category:{{Name|arma3}}: Functions|{{uc:selectRandomWeighted}}]]
[[Category:{{Name|tkoh}}: Functions|{{uc:selectRandomWeighted}}]]

Latest revision as of 16:41, 13 July 2022

Hover & click on the images for description

Description

Description:
Selects a random item from an array, taking into account item weight.
  • 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
Arma 3
See selectRandomWeighted for an engine solution.
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:
[["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