selectRandomWeighted: Difference between revisions
Jump to navigation
Jump to search
Killzone Kid (talk | contribs) (Created page with "{{Command|= Comments ____________________________________________________________________________________________ |arma3dev|= Game name |1.73|= Game version ________________...") |
Killzone Kid (talk | contribs) mNo edit summary |
||
Line 11: | Line 11: | ||
* If an item's weight is 0, the item is ignored | * If an item's weight is 0, the item is ignored | ||
* Weight strength is relative and calculated from the range [0 ... maxWeight] | * Weight strength is relative and calculated from the range [0 ... maxWeight] | ||
* If numbers of items and weights do not match, the shortest array is used |= Description | * If numbers of items and weights do not match, the shortest array is used | ||
* A single array Syntax is slightly faster then Alt Syntax |= Description | |||
____________________________________________________________________________________________ | ____________________________________________________________________________________________ | ||
Revision as of 20:10, 26 June 2017
Description
- Description:
- Returns a random element from the given array according to assigned weights. Engine solution to BIS_fnc_selectRandomWeighted. A few notes:
- Negative weights are not supported
- If an item's weight is 0, the item is ignored
- Weight strength is relative and calculated from the range [0 ... maxWeight]
- If numbers of items and weights do not match, the shortest array is used
- A single array Syntax is slightly faster then Alt Syntax
- Groups:
- Uncategorised
Syntax
- Syntax:
- selectRandomWeighted valuesAndWeights
- Parameters:
- valuesAndWeights: Array - array in format [value1, weight1, value2, weight2...], where:
- Return Value:
- Anything - random weighted value or Nothing if array is empty or all weights are 0
Alternative Syntax
- Syntax:
- values selectRandomWeighted weights
- Parameters:
- values: Array - array of Anything
- weights: Array - array of Numbers
- Return Value:
- Anything - random weighted value or Nothing if any of arrays is empty or all weights are 0
Examples
- Example 1:
_randomWeightedElement = selectRandomWeighted [1,0.1,2,0.2,3,1.3,4,2.4,5,7.5];
- Example 2:
_randomWeightedElement = [1,2,3,4,5] selectRandomWeighted [0.1,0.2,1.3,2.4,7.5];
Additional Information
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
[[Category:Introduced with arma3dev version 1.73]][[ Category: arma3dev: New Scripting Commands | SELECTRANDOMWEIGHTED]][[ Category: arma3dev: Scripting Commands | SELECTRANDOMWEIGHTED]]