{"name":"BIS_fnc_selectRandomWeighted","title":"BIS fnc selectRandomWeighted","type":"function","url":"https://community.bistudio.com/wiki/BIS_fnc_selectRandomWeighted","revid":327996,"updated":"2022-07-13T15:41:47Z","groups":["Arrays"],"status":"ok","games":{"arma2":"1.00","arma2oa":"1.50","tkoh":"1.00","arma3":"0.50"},"since":"arma2 1.00","arma3_since":"0.50","description":"Selects a random item from an array, taking into account item weight.\n\n> [!NOTE]\n> - The weights do not have to total to 1\n> - The length of weights and items arrays may not match, in which case the shortest array is used for length\n\n> [!NOTE]\n> **Arma 3:** See selectRandomWeighted for an engine solution.","syntaxes":[{"syntax":"itemsAndWeights call BIS_fnc_selectRandomWeighted","params":[{"name":"itemsAndWeights","type":"Array","description":"array of items and weights [item, weight, item, weight...]","type_expr":"Array"}],"returns":{"type":"Anything","type_expr":"Anything"}},{"syntax":"[items, weights] call BIS_fnc_selectRandomWeighted","params":[{"name":"items","type":"Array","description":"items array of Anything","type_expr":"Array"},{"name":"weights","type":"Array","description":"weights array of Numbers","type_expr":"Array"}],"returns":{"type":"Anything","type_expr":"Anything"}}],"examples":[{"code":["[\"apples\",.3,\"pears\",.2,\"bananas\",.4,\"diamonds\",.1,\"unicorns\",.00001] call BIS_fnc_selectRandomWeighted;"]},{"code":["[[\"apples\",\"pears\",\"bananas\",\"diamonds\"], [0.3,0.2,0.4,0.1]] call BIS_fnc_selectRandomWeighted;"]}],"see_also":["selectRandomWeighted"]}