{"name":"selectRandomWeighted","operator":null,"title":"selectRandomWeighted","type":"command","url":"https://community.bistudio.com/wiki/selectRandomWeighted","revid":377677,"updated":"2026-01-02T09:02:40Z","groups":["Arrays"],"status":"ok","replaced_by":[],"games":[{"game":"arma3","name":"Arma 3","version":"1.76"}],"since":{"game":"arma3","name":"Arma 3","version":"1.76"},"arma3_since":"1.76","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"description":"Returns a random element from the given array according to assigned weights. Engine solution to BIS_fnc_selectRandomWeighted. A few notes:\n- Negative weights are not supported\n- If an item's weight is 0, the item is ignored\n- The weights don't have to total to 1\n- If numbers of items and weights do not match, the shortest array is used\n- A single array Syntax is slightly faster than Alt Syntax","syntaxes":[{"syntax":"selectRandomWeighted valuesAndWeights","since":null,"effect":null,"exec":null,"params":[{"name":"valuesAndWeights","type":"Array with [valueN, weightN]","optional":false,"default":null,"description":"Array with [valueN, weightN]\n- valueN: Anything - weighted value\n- weightN: Number - values relative weight","types":["Array"],"since":null,"text":"valuesAndWeights: Array with [valueN, weightN]\n- valueN: Anything - weighted value\n- weightN: Number - values relative weight"}],"returns":{"type":"Anything","types":["Anything"],"description":"random weighted value or Nothing if array is empty or all weights are 0","text":"Anything - random weighted value or Nothing if array is empty or all weights are 0"},"form":"unary","operator":null,"left":null,"right":{"text":"valuesAndWeights","types":["Array"]}},{"syntax":"values selectRandomWeighted weights","since":null,"effect":null,"exec":null,"params":[{"name":"values","type":"Array of Anything","optional":false,"default":null,"description":null,"types":["Array","Anything"],"since":null,"text":"values: Array of Anything"},{"name":"weights","type":"Array of Numbers","optional":false,"default":null,"description":null,"types":["Array","Number"],"since":null,"text":"weights: Array of Numbers"}],"returns":{"type":"Anything","types":["Anything"],"description":"random weighted value or Nothing if any of arrays is empty or all weights are 0","text":"Anything - random weighted value or Nothing if any of arrays is empty or all weights are 0"},"form":"binary","operator":null,"left":{"text":"values","types":["Array","Anything"]},"right":{"text":"weights","types":["Array","Number"]}}],"examples":[{"text":"```sqf\nprivate _randomWeightedElement = selectRandomWeighted [1,0.1,2,0.2,3,1.3,4,2.4,5,7.5];\n```","code":["private _randomWeightedElement = selectRandomWeighted [1,0.1,2,0.2,3,1.3,4,2.4,5,7.5];"]},{"text":"```sqf\nprivate _randomWeightedElement = [1,2,3,4,5] selectRandomWeighted [0.1,0.2,1.3,2.4,7.5];\n```","code":["private _randomWeightedElement = [1,2,3,4,5] selectRandomWeighted [0.1,0.2,1.3,2.4,7.5];"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["random","select","selectRandom","selectMin","selectMax"],"notes":[{"user":"Killzone_Kid","date":"2017-06-26T19:17:00Z","text":"A 100000 runs of the following code:\n\n```sqf\n_values = [0,1,2,3,4,5,6,7,8,9];\n_weights = [0.109,0.65,0.01,1.01,1.24,0,1.59,0.09,1.15,0.55];\n_result = _values selectRandomWeighted _weights;\n```\n\nGave this result:\n\n```\n0 - 0\n0.01 - 144\n0.09 - 1409\n0.109 - 1633\n0.55 - 8673\n0.65 - 10127\n1.01 - 15668\n1.15 - 18059\n1.24 - 19518\n1.59 - 24769\n```"}],"categories":["Arma 3: New Scripting Commands","Arma 3: Scripting Commands","Command Group: Arrays","Introduced with Arma 3 version 1.76","Scripting Commands"]}