BIS fnc selectRandomWeighted: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - " *\|= * " to " ")
m (Text replacement - " *\| *([Cc]omments|COMMENTS|[Gg]ame [Nn]ame|Game [Vv]ersion|Game Version \(number surrounded by NO SPACES\)|Multiplayer Arguments \("local" or "global"\)|Multiplayer Effects \("local" or "global"\)|Multiplayer Execution \("server" o...)
Line 1: Line 1:
{{Function|Comments=
{{Function


| arma2 |Game name=
| arma2


|1.00|Game version=
|1.00


|gr1= Arrays |GROUP1=
|gr1= Arrays


| 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:
Line 11: Line 11:
* 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=
| itemsAndWeights call [[BIS_fnc_selectRandomWeighted]]


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


| [[Anything]] |RETURNVALUE=
| [[Anything]]


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


|p21=[items, weights]: [[Array]]|PARAMETER21=
|p21=[items, weights]: [[Array]]|PARAMETER21=
Line 27: Line 27:
|p23=weights: [[Array]] - weights array of [[Number]]s |PARAMETER23=
|p23=weights: [[Array]] - weights array of [[Number]]s |PARAMETER23=


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


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


| [[selectRandomWeighted]]|SEEALSO=
| [[selectRandomWeighted]]


}}
}}

Revision as of 23:48, 17 January 2021

Hover & click on the images for description

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
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, 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

Bottom Section