{"name":"BIS_fnc_selectRandomWeighted","operator":null,"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","replaced_by":[],"games":[{"game":"arma2","name":"Arma 2","version":"1.00"},{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.50"},{"game":"tkoh","name":"Take On Helicopters","version":"1.00"},{"game":"arma3","name":"Arma 3","version":"0.50"}],"since":{"game":"arma2","name":"Arma 2","version":"1.00"},"arma3_since":"0.50","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"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","since":null,"effect":null,"exec":null,"params":[{"name":"itemsAndWeights","type":"Array","optional":false,"default":null,"description":"array of items and weights [item, weight, item, weight...]","types":["Array"],"since":null,"text":"itemsAndWeights: Array - array of items and weights [item, weight, item, weight...]"}],"returns":{"type":"Anything","types":["Anything"],"description":null,"text":"Anything"}},{"syntax":"[items, weights] call BIS_fnc_selectRandomWeighted","since":null,"effect":null,"exec":null,"params":[{"name":"items","type":"Array","optional":false,"default":null,"description":"items array of Anything","types":["Array"],"since":null,"text":"items: Array - items array of Anything"},{"name":"weights","type":"Array","optional":false,"default":null,"description":"weights array of Numbers","types":["Array"],"since":null,"text":"weights: Array - weights array of Numbers"}],"returns":{"type":"Anything","types":["Anything"],"description":null,"text":"Anything"}}],"examples":[{"text":"```sqf\n[\"apples\",.3,\"pears\",.2,\"bananas\",.4,\"diamonds\",.1,\"unicorns\",.00001] call BIS_fnc_selectRandomWeighted;\n```","code":["[\"apples\",.3,\"pears\",.2,\"bananas\",.4,\"diamonds\",.1,\"unicorns\",.00001] call BIS_fnc_selectRandomWeighted;"]},{"text":"```sqf\n[[\"apples\",\"pears\",\"bananas\",\"diamonds\"], [0.3,0.2,0.4,0.1]] call BIS_fnc_selectRandomWeighted;\n```","code":["[[\"apples\",\"pears\",\"bananas\",\"diamonds\"], [0.3,0.2,0.4,0.1]] call BIS_fnc_selectRandomWeighted;"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["selectRandomWeighted"],"notes":[],"categories":["Arma 2: Functions","Arma 2: New Functions","Arma 2: Operation Arrowhead: Functions","Arma 3: Functions","Function Group: Arrays","Functions","Introduced with Arma 2 version 1.00","Take On Helicopters: Functions"],"docblock":null,"filled_from_docblock":[]}