# selectRandom ## Category Random ## Arity **Unary** — `selectRandom `. ``` selectRandom ``` ## Description Picks and returns a **random element** from the array. Each element has equal probability. Returns `nil` if the array is empty. ## How It Works Generates a random index from `0` to `count-1` using the thread-safe RNG, then returns `array[index]`. All elements have uniform probability. ## Usage ### Basic random pick ```sqf _color = selectRandom ["red", "green", "blue"]; _sound = selectRandom _soundArray; ``` ### Random spawn position ```sqf _spawnPos = selectRandom _spawnPoints; ``` ### Random AI behavior ```sqf _behavior = selectRandom ["patrol", "guard", "idle", "search"]; _unit setBehavior _behavior; ``` ### Empty array guard ```sqf _result = selectRandom _arr; if (isNil "_result") then { systemChat "No items available"; }; ``` ### Dice table simulation ```sqf _lootTable = ["common", "common", "common", "common", "rare", "epic"]; _loot = selectRandom _lootTable; // 4/6 common, 1/6 rare, 1/6 epic ``` ## Thread Safety ReadOnly on the array — only reads the array content. The internal RNG is thread-safe. Array must be accessible from current scheduler (frozen OK, mutable owned OK). ## See Also - [random](random.md) — random float - [selectRandomWeighted](selectRandomWeighted.md) — weighted random pick - [select](select.md) — deterministic element access - [count](count.md) — array length