GameplayJava

/random

Generates a pseudorandom number in a given range (value), or rolls and broadcasts it (roll), optionally tied to a named, reproducible sequence so datapacks can get deterministic randomness. Added in 1.20.2.

What is /random used for?

What /random is for

Generates a pseudorandom number in a range, or rolls and broadcasts one, optionally on a named reproducible sequence. Added in 1.20.2.

When to use /random

Add dice rolls and randomized outcomes to datapacks. Pair /random value with /execute store to read the result into a scoreboard.

Syntax

Parameters

action
literal
value, roll, or reset.
range
int range
e.g. 1..6 for a six-sided die.
sequenceoptional
namespaced ID
Named sequence for reproducible rolls.

Examples

  • Get a random number from 1 to 6 (use in execute store).

  • Roll a d20 on a named sequence and broadcast it.

Permission level

/random requires Cheats (op level 2). In single-player you need the world's "Allow Cheats" toggle on. On a multiplayer server you need to be opped — see /op.