{"name":"random","operator":null,"title":"random","type":"command","url":"https://community.bistudio.com/wiki/random","revid":377710,"updated":"2026-01-02T09:03:49Z","groups":["Math"],"status":"ok","replaced_by":[],"games":[{"game":"ofp","name":"Operation Flashpoint","version":"1.00"},{"game":"ofpe","name":"Operation Flashpoint: Elite","version":"1.00"},{"game":"arma1","name":"Armed Assault","version":"1.00"},{"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":"ofp","name":"Operation Flashpoint","version":"1.00"},"arma3_since":"0.50","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"description":"|  |  |\n|---|---|\n|  |  |\n\n|  |  |\n|---|---|\n| #Syntax 1 | generates a random floating point value |\n| #Syntax 2 | generates a [Gaussian Distribution](https://en.wikipedia.org/wiki/Normal_distribution) (ref: Technically, it is a rescaled <https://en.wikipedia.org/wiki/Bates_distribution> with n = 4.<br>The distribution is split in two at its midpoint and scaled linearly such that its maximum lies at the specified midpoint.). It uses the same method as setTriggerTimeout command and is quite useful for e.g spawning loot, making more valuable items more rare |\n| #Syntax 3 | generates a [seed-based](https://en.wikipedia.org/wiki/Random_seed) random number |\n| #Syntax 4 | generates a [seed-based](https://en.wikipedia.org/wiki/Random_seed) random noise (**not** Perlin) texture based on provided seed and returning the value at supplied coordinates |","syntaxes":[{"syntax":"random x","since":null,"effect":null,"exec":null,"params":[{"name":"x","type":"Number","optional":false,"default":null,"description":null,"types":["Number"],"since":null,"text":"x: Number"}],"returns":{"type":null,"types":["Number"],"description":null,"text":"Number from 0 (included) to *x*, **ex**cluded\n\n> [!IMPORTANT]\n> *x* was accidentally **in**cluded due to a bug introduced in Arma 2 v1.00 and fixed in Arma 3 v2.18."},"form":"unary","operator":null,"left":null,"right":{"text":"x","types":["Number"]}},{"syntax":"random [min, mid, max]","since":"arma3 1.56","effect":null,"exec":null,"params":[{"name":"min","type":"Number","optional":false,"default":null,"description":null,"types":["Number"],"since":null,"text":"min: Number"},{"name":"mid","type":"Number","optional":false,"default":null,"description":null,"types":["Number"],"since":null,"text":"mid: Number"},{"name":"max","type":"Number","optional":false,"default":null,"description":null,"types":["Number"],"since":null,"text":"max: Number"}],"returns":{"type":"Number in range from min to max, weighted by mid","types":["Number"],"description":"can be higher than max (maximum value is `min + max - mid`)","text":"Number in range from *min* to *max*, weighted by *mid* - **can** be higher than max (maximum value is `min + max - mid`)"},"form":"unary","operator":null,"left":null,"right":{"text":"[min, mid, max]","types":["Array"]}},{"syntax":"seed random x","since":"arma3 1.68","effect":null,"exec":null,"params":[{"name":"seed","type":"Number","optional":false,"default":null,"description":"an **integer**. Any float value will be truncated (e.g -0.9, -0.1, 0.1 or 0.9 will be read as **0**)","types":["Number"],"since":null,"text":"seed: Number - an **integer**. Any float value will be truncated (e.g -0.9, -0.1, 0.1 or 0.9 will be read as **0**)"},{"name":"x","type":"Number","optional":false,"default":null,"description":null,"types":["Number"],"since":null,"text":"x: Number"}],"returns":{"type":"Number from 0 (included) to x (included)","types":["Number"],"description":null,"text":"Number from 0 (included) to *x* (**in**cluded)"},"form":"binary","operator":null,"left":{"text":"seed","types":["Number"]},"right":{"text":"x","types":["Number"]}},{"syntax":"seed random [x, y]","since":"arma3 1.68","effect":null,"exec":null,"params":[{"name":"seed","type":"Number","optional":false,"default":null,"description":null,"types":["Number"],"since":null,"text":"seed: Number"},{"name":"x","type":"Number","optional":false,"default":null,"description":"x texture position","types":["Number"],"since":null,"text":"x: Number - x texture position"},{"name":"y","type":"Number","optional":false,"default":null,"description":"y texture position","types":["Number"],"since":null,"text":"y: Number - y texture position"}],"returns":{"type":"Number from 0 (included) to 1 (excluded)","types":["Number"],"description":null,"text":"Number from 0 (included) to 1 (**ex**cluded)"},"form":"binary","operator":null,"left":{"text":"seed","types":["Number"]},"right":{"text":"[x, y]","types":["Array"]}}],"examples":[{"text":"```sqf\n_rNumber = random 1;\n```","code":["_rNumber = random 1;"]},{"text":"```sqf\n_rNumber = random -10;\n```","code":["_rNumber = random -10;"]},{"text":"Generate a random position inside a circle (see also Example Code: Random Area Distribution)\n\n```sqf\n_center getPos [_radius * sqrt random 1, random 360];\n```","code":["_center getPos [_radius * sqrt random 1, random 360];"]},{"text":"Select a random value from an array:\n\n```sqf\n_array = [\"apples\", \"pears\", \"bananas\", \"M16\"];\n\n_random = _array select floor random count _array;    // before Arma 2\n_random = _array call BIS_fnc_selectRandom;            // since Arma 2\n_random = selectRandom _array;                        // since Arma 3 v1.56\n```","code":["_array = [\"apples\", \"pears\", \"bananas\", \"M16\"];\n\n_random = _array select floor random count _array;\t// before Arma 2\n_random = _array call BIS_fnc_selectRandom;\t\t\t// since Arma 2\n_random = selectRandom _array;\t\t\t\t\t\t// since Arma 3 v1.56"]},{"text":"Visualisation of #Syntax 4 (warning, it takes a bit to execute and draw):\n\n```sqf\nprivate _parent = call BIS_fnc_displayMission;\nif (is3DEN) then { _parent = findDisplay 313 };\nprivate _display = _parent createDisplay \"RscDisplayEmpty\";\nprivate _background = _disp ctrlCreate [\"RscBackground\", -1];\n\nprivate _coef = 0.1;\n\nfor \"_x\" from 1 to 100 do\n{\n    for \"_y\" from 1 to 100 do\n    {\n        private _random = 0 random [_x * _coef, _y * _coef];\n        private _dot = _display ctrlCreate [\"RscBackground\", -1];\n\n        _dot ctrlSetPosition [0.5 + pixelW * _x, 0.5 + pixelH * _y, pixelW, pixelH];\n        _dot ctrlSetBackgroundColor [_random, _random, _random, 1];\n        _dot ctrlCommit 0;\n    };\n};\n```","code":["private _parent = call BIS_fnc_displayMission;\nif (is3DEN) then { _parent = findDisplay 313 };\nprivate _display = _parent createDisplay \"RscDisplayEmpty\";\nprivate _background = _disp ctrlCreate [\"RscBackground\", -1];\n\nprivate _coef = 0.1;\n\nfor \"_x\" from 1 to 100 do\n{\n\tfor \"_y\" from 1 to 100 do\n\t{\n\t\tprivate _random = 0 random [_x * _coef, _y * _coef];\n\t\tprivate _dot = _display ctrlCreate [\"RscBackground\", -1];\n\n\t\t_dot ctrlSetPosition [0.5 + pixelW * _x, 0.5 + pixelH * _y, pixelW, pixelH];\n\t\t_dot ctrlSetBackgroundColor [_random, _random, _random, 1];\n\t\t_dot ctrlCommit 0;\n\t};\n};"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["selectRandom","selectRandomWeighted","Example Code: Random Area Distribution"],"notes":[{"user":"Hcpookie","date":"2015-07-12T20:32:00Z","text":"Random selections including negative numbers can be obtained via:\n\n```sqf\n_xRnd = round (random 200) - 100;\n```\n\nThis will yield numbers between -100 and 100.\n- Be careful using random numbers in multiplayer, each client will come up with a different result. See multiplayer tutorials for more general information about locality.\n- The number returned is unlikely to be a whole number.\n\nTo return a whole number use either **round**, **ceil** or **floor** together with random\n\n```sqf\nx = round    (random 5) // will return 0, 1, 2, 3, 4 or 5.    (non-uniform distribution, 0 and 5 are half as likely to be selected than any of the other numbers)\nx = floor    (random 5) // will return 0, 1, 2, 3 or 4.        (uniform distribution, all numbers have the same probability of being selected)\nx = ceil    (random 5) // will return 0, 1, 2, 3, 4 or 5.    (0 is very unlikely, but possible, as ceil 0 is 0)\n```"},{"user":"Lou Montana","date":"2018-07-22T12:58:00Z","text":"|  |  |  |  |  |  |  |  |  |  |  |  |\n|---|---|---|---|---|---|---|---|---|---|---|---|\n| + Repartition comparison | Formula | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |\n| ```sqf<br>floor random 10<br>``` | 10% | 10% | 10% | 10% | 10% | 10% | 10% | 10% | 10% | 10% |  |\n| ```sqf<br>floor random [0, 5, 10]<br>``` | 0% | 2% | 7% | 17% | 25% | 25% | 17% | 7% | 2% | 0% |  |\n| ```sqf<br>floor random [0, 10, 0]<br>``` | 0% | 0% | 1% | 2% | 5% | 9% | 14% | 19% | 24% | 26% |  |\n| ```sqf<br>floor random [0, 10, 5]<br>``` | 0% | 0% | 0% | 1% | 2% | 5% | 9% | 16% | 28% | 38% |  |"}],"categories":["ArmA: Armed Assault: Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 2: Scripting Commands","Arma 3: Scripting Commands","Command Group: Math","Introduced with Operation Flashpoint version 1.00","Operation Flashpoint: Elite: Scripting Commands","Operation Flashpoint: New Scripting Commands","Operation Flashpoint: Scripting Commands","Scripting Commands","Take On Helicopters: Scripting Commands"]}