Overview
When you want your island to feel alive and unpredictable, hard-coded values are the enemy. GetRandomInt(Low, High) returns a uniformly distributed integer anywhere from Low to High inclusive — both endpoints can be hit, and the two arguments can even be out of order. Its sibling GetRandomFloat(Low, High) does the same for decimal values, and Shuffle() randomises an entire array in one call.
Think of a clifftop fishing cove where the score you earn for each catch is never the same, or a dock where a random number of supply crates wash ashore each round. These are the moments GetRandomInt was made for.
When to reach for it:
- Random score bonuses or penalties
- Picking a random item from an array (random index)
- Deciding how many objects to spawn
- Any weighted or chance-based branch in game logic
API Reference
(API surface could not be resolved for this device.)
Walkthrough
Scenario: A sunny fishing dock on Verse Island. When a player steps on a pressure plate at the end of the pier, they earn a random score bonus between 10 and 100 points — simulating the thrill of landing a big catch. A second plate on the clifftop awards a smaller, float-scaled bonus to show GetRandomFloat in action. The score manager device records everything.
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/Random }
# Place this Verse device on your island alongside:
# - Two trigger_device objects (DockPlate, ClifftopPlate)
# - One score_manager_device (ScoreManager)
dock_fishing_device := class(creative_device):
# The pressure plate at the end of the dock
@editable
DockPlate : trigger_device = trigger_device{}
# The pressure plate on the clifftop above the cove
@editable
ClifftopPlate : trigger_device = trigger_device{}
# Awards points to the triggering player
@editable
ScoreManager : score_manager_device = score_manager_device{}
# Called once when the island starts
OnBegin<override>()<suspends> : void =
# Subscribe both plates to their handlers
DockPlate.TriggeredEvent.Subscribe(OnDockStep)
ClifftopPlate.TriggeredEvent.Subscribe(OnClifftopStep)
# Fires when a player steps on the dock plate
# Agent is ?agent — unwrap before use
OnDockStep(Agent : ?agent) : void =
if (A := Agent?):
# Random integer catch bonus: 10 to 100 gold coins
BonusPoints : int = GetRandomInt(10, 100)
# Award the score once per coin of bonus
# (score_manager_device.Increment adds 1 each call;
# we loop BonusPoints times then Activate to pay out)
var Ticks : int = 0
loop:
if (Ticks >= BonusPoints):
break
ScoreManager.Increment(A)
set Ticks = Ticks + 1
ScoreManager.Activate(A)
# Fires when a player steps on the clifftop plate
OnClifftopStep(Agent : ?agent) : void =
if (A := Agent?):
# Random integer bonus: 10 to 40 points (simulating 0.5x to 2.0x of 20)
BonusPoints : int = GetRandomInt(10, 40)
var Ticks : int = 0
loop:
if (Ticks >= BonusPoints):
break
ScoreManager.Increment(A)
set Ticks = Ticks + 1
ScoreManager.Activate(A)```
**Line-by-line breakdown:**
| Lines | What's happening |
|---|---|
| `@editable` fields | Wire up your placed devices in the UEFN editor — the Verse class holds references, not the devices themselves. |
| `OnBegin` | Subscribes both trigger events before any player can step on a plate. |
| `OnDockStep(Agent : ?agent)` | `trigger_device.TriggeredEvent` sends `?agent` — always optional, always unwrap with `if (A := Agent?):`. |
| `GetRandomInt(10, 100)` | Returns a whole number from 10 to 100 inclusive. Different every time a player steps on the plate. |
| `Increment` loop + `Activate` | `score_manager_device` accumulates increments then pays them out on `Activate`. |
| `GetRandomFloat(0.5, 2.0)` | Returns a decimal multiplier; multiply by the base, then convert to `int` with `Int[…]`. |
## Common patterns
### Pattern 1 — Pick a random item from an array
You have a shore-side loot table. Use `GetRandomInt` as an array index to pick one item at random.
```verse
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/Random }
# Demonstrates random array indexing with item_spawner_device
random_loot_picker := class(creative_device):
# Three item spawners placed at the cove, each configured for a different item
@editable
LootSpawners : []item_spawner_device = array{}
# A trigger that fires when a player opens the supply crate
@editable
CrateTrigger : trigger_device = trigger_device{}
OnBegin<override>()<suspends> : void =
CrateTrigger.TriggeredEvent.Subscribe(OnCrateOpened)
OnCrateOpened(Agent : ?agent) : void =
# Guard: need at least one spawner
if (LootSpawners.Length > 0):
# Random index from 0 to last valid index
RandomIndex : int = GetRandomInt(0, LootSpawners.Length - 1)
if (Spawner := LootSpawners[RandomIndex]):
Spawner.SpawnItem()
Pattern 2 — Shuffle an array for a randomised wave order
Each round on the dock, enemies should arrive in a different order. Shuffle rearranges the whole array.
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/Random }
# Demonstrates Shuffle() for randomised spawn sequences
wave_shuffle_device := class(creative_device):
# Guard spawners placed around the cove — each spawns a different NPC type
@editable
GuardSpawners : []creature_spawner_device = array{}
# A trigger that starts the wave (e.g. a round-start trigger)
@editable
WaveStartTrigger : trigger_device = trigger_device{}
OnBegin<override>()<suspends> : void =
WaveStartTrigger.TriggeredEvent.Subscribe(OnWaveStart)
OnWaveStart(Agent : ?agent) : void =
# Shuffle the spawner array — different order every round
ShuffledSpawners : []creature_spawner_device = Shuffle(GuardSpawners)
for (Spawner : ShuffledSpawners):
Spawner.Spawn()
Pattern 3 — Random score penalty (score_manager_device.Decrement)
A dock hazard zone: stepping on the slippery plank deducts a random number of points.
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/Random }
# Demonstrates GetRandomInt for a penalty mechanic
slippery_plank_device := class(creative_device):
@editable
PlankTrigger : trigger_device = trigger_device{}
@editable
ScoreManager : score_manager_device = score_manager_device{}
OnBegin<override>()<suspends> : void =
PlankTrigger.TriggeredEvent.Subscribe(OnSlip)
OnSlip(Agent : ?agent) : void =
if (A := Agent?):
# Penalty between 5 and 30 points — ouch!
Penalty : int = GetRandomInt(5, 30)
var Ticks : int = 0
loop:
if (Ticks >= Penalty):
break
ScoreManager.Decrement(A)
set Ticks = Ticks + 1
ScoreManager.Activate(A)
Gotchas
1. You must using { /Verse.org/Random }
GetRandomInt, GetRandomFloat, and Shuffle all live in the /Verse.org/Random module. Without the using directive the compiler reports Unknown identifier: GetRandomInt. Add it at the top of every file that calls these functions.
2. GetRandomInt has the <transacts> effect
This means it can be called inside transactional contexts (like <decides> expressions) but it also means it cannot be called in a <no_rollback> context. In practice, calling it from a normal event handler or OnBegin is always fine.
3. Both bounds are inclusive
GetRandomInt(1, 6) can return 1, 2, 3, 4, 5, or 6 — just like a real die. When using it as an array index, pass LootSpawners.Length - 1 as the upper bound, not LootSpawners.Length, or you'll get an out-of-bounds failure.
4. No automatic int↔float conversion
Verse is strict about types. GetRandomFloat returns a float; if you need an int, convert explicitly with Int[MyFloat] (which is a failable expression — use it inside an if or after confirming the value is in range). Never pass a float where an int is expected or vice versa.
5. Unwrap ?agent before doing anything with it
trigger_device.TriggeredEvent sends ?agent (an optional). Always unwrap: if (A := Agent?): before passing A to ScoreManager.Activate(A) or any other agent-accepting API. Skipping the unwrap is a compile error.
6. Shuffle returns a new array — the original is unchanged
Verse arrays are value types. Shuffle(GuardSpawners) gives you a fresh shuffled copy; GuardSpawners itself stays in its original order. Assign the result to a new variable.