-
Notifications
You must be signed in to change notification settings - Fork 0
selectRandom
ffredyk edited this page Jul 23, 2026
·
1 revision
Random
Unary — selectRandom <array>.
selectRandom <array>
Picks and returns a random element from the array. Each element has equal probability. Returns nil if the array is empty.
Generates a random index from 0 to count-1 using the thread-safe RNG, then returns array[index]. All elements have uniform probability.
_color = selectRandom ["red", "green", "blue"];
_sound = selectRandom _soundArray;_spawnPos = selectRandom _spawnPoints;_behavior = selectRandom ["patrol", "guard", "idle", "search"];
_unit setBehavior _behavior;_result = selectRandom _arr;
if (isNil "_result") then {
systemChat "No items available";
};_lootTable = ["common", "common", "common", "common", "rare", "epic"];
_loot = selectRandom _lootTable; // 4/6 common, 1/6 rare, 1/6 epicReadOnly 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).
- random — random float
- selectRandomWeighted — weighted random pick
- select — deterministic element access
- count — array length
- Getting Started
- Language Guide
- Type System
- Control Flow
- Functions & Code
- Strings & Text
- Arrays & Collections
- Concurrency
- Promise System
- Thread Safety
- Host API & Embedding
- CLI Tool
- Bytecode Reference
- Multiplayer
- Syntax Sugar
- Optimization Guide
- Benchmarks
- count
- select
- pushBack
- append
- deleteAt
- deleteRange
- resize
- reverse
- sort
- find
- in
- forEach
- freeze
- thaw
- isFrozen
- currentScheduler
- clientOwner
- allSchedulers
- schedulerName
- schedulerExists
- schedulerBudget
- setSchedulerBudget
- fiberCount
- readyFiberCount
- waitingFiberCount
- schedulerLoad
- sendTo