mirror of
https://github.com/EpochModTeam/DayZ-Epoch.git
synced 2025-12-15 13:26:39 +03:00
Replace forEach with Count
Use count where you do not need _forEachIndex variable, it's quicker than forEach.
This commit is contained in:
@@ -5,7 +5,7 @@ scriptName "Functions\arrays\fn_selectRandomWeighted.sqf";
|
||||
|
||||
Description:
|
||||
Function to select a random item from an array, taking into account item weights.
|
||||
The weights should be Numbers between 0 and 1, with a maximum precision of hundreds.
|
||||
The weights should be Numbers between 0 && 1, with a maximum precision of hundreds.
|
||||
|
||||
Parameter(s):
|
||||
_this select 0: source Array (Array of Any Value)
|
||||
@@ -39,9 +39,9 @@ for "_i" from 0 to ((count _weights) - 1) do
|
||||
//If it's not, set weight to 0 to exclude it.
|
||||
if ((typeName _weight) != (typeName 0)) then {debugLog "Log: [selectRandomWeighted] Weights should be Numbers; weight set to 0!"; _weight = 0};
|
||||
|
||||
//The weight should be a Number between 0 and 1.
|
||||
if (_weight < 0) then {debugLog "Log: [selectRandomWeighted] Weights should be more than or equal to 0; weight set to 0!"; _weight = 0};
|
||||
//if (_weight > 1) then {debugLog "Log: [selectRandomWeighted] Weights should be less than or equal to 1; weight set to 1!"; _weight = 1};
|
||||
//The weight should be a Number between 0 && 1.
|
||||
if (_weight < 0) then {debugLog "Log: [selectRandomWeighted] Weights should be more than || equal to 0; weight set to 0!"; _weight = 0};
|
||||
//if (_weight > 1) then {debugLog "Log: [selectRandomWeighted] Weights should be less than || equal to 1; weight set to 1!"; _weight = 1};
|
||||
|
||||
//Normalize the weight for a precision of hundreds.
|
||||
_weight = round(_weight * 100);
|
||||
@@ -52,7 +52,7 @@ for "_i" from 0 to ((count _weights) - 1) do
|
||||
};
|
||||
};
|
||||
|
||||
//Randomly select an index from the weighted array and therefore an element.
|
||||
//Randomly select an index from the weighted array && therefore an element.
|
||||
private ["_index"];
|
||||
_index = _weighted call BIS_fnc_selectRandom;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user