Skip to content
ffredyk edited this page Jul 23, 2026 · 1 revision

random

Category

Random

Arity

Unaryrandom <max>.

random <number>

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

_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

// Random between min and max
_randInRange = _min + random (_max - _min);

Probability check

if (random 100 < 30) then {    // 30% chance
    spawnRareLoot();
};

Random position jitter

_x = _baseX + random _width;
_y = _baseY + random _height;

Random angle

_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

SQ# Wiki

Home

Engine Docs

Migration

Commands

Value Constructors

Arithmetic

Comparison

Logic

Array

String

Math

Random

Type & Introspection

HashMap

Code Execution

Concurrency

Scheduler

Thread Safety

Error

Output

Time

Multiplayer

Compiler

Clone this wiki locally