# random ## Category Random ## Arity **Unary** — `random `. ``` random ``` ## Description Returns a random floating-point number in the range `[0, max)`. The value is >= 0 and < max. Uses a **thread-safe** random number generator (internal lock). Auto-unwraps `shared` values. ## How It Works Uses a shared `System.Random` instance with internal locking for thread safety. Generates a `double` in `[0.0, max)`. The lock ensures correct behavior under concurrent access but may be a contention point under heavy multi-threaded use. ## Usage ### Basic random ```sqf _dice = random 6; // 0.0 to 5.999... _roll = floor random 6; // integer 0 to 5 _roll = floor random 6 + 1; // integer 1 to 6 ``` ### Random range ```sqf // Random between min and max _randInRange = _min + random (_max - _min); ``` ### Probability check ```sqf if (random 100 < 30) then { // 30% chance spawnRareLoot(); }; ``` ### Random position jitter ```sqf _x = _baseX + random _width; _y = _baseY + random _height; ``` ### Random angle ```sqf _angle = random 360; _rad = _angle * 3.14159265 / 180; ``` ## Thread Safety **Thread-safe** — internal lock protects the RNG state. Safe to call from any scheduler concurrently. Note: lock contention may occur under extreme multi-threaded load. ## See Also - [selectRandom](selectRandom.md) — random element from array - [selectRandomWeighted](selectRandomWeighted.md) — weighted random pick - [floor](floor.md) — convert to integer