Updated:

The basic form

/random value 1..6
/random roll 1..6

Both pick a number from 1 to 6. The difference is who sees it.

FormWho sees the resultUse it for
valueOnly the senderUsing the number in other commands
rollEveryone, in chatRolling a die in front of other players

Write the range as min..max with both ends. An open range such as 1.. is not accepted.

Save the result to a score

/scoreboard objectives add dice dummy
/execute store result score @p dice run random value 1..6
/tellraw @a ["",{"selector":"@p"},{"text":" rolled "},{"score":{"name":"@p","objective":"dice"}}]

Line 1 creates the score, line 2 stores the roll and line 3 announces it. The tellraw guide covers the message format.

Do different things for each result

/execute if score @p dice matches 6 run give @p minecraft:diamond 1
/execute if score @p dice matches 1..5 run say No luck!

matches 6 means "is 6" and matches 1..5 means "1 to 5". To set odds, change the range: roll 1..100 and treat matches 1..10 as a win for a 10% chance.

Pick one player

To choose a single player, the @r selector is simpler than /random.

/tag @r add winner
/tellraw @a ["",{"selector":"@a[tag=winner]"},{"text":" wins!","color":"gold"}]

Clear the tag with /tag @a remove winner before the next draw. See the tag guide.

Repeatable rolls with a sequence

/random value 1..6 mygame:dice
/random reset mygame:dice 12345

Adding a sequence ID gives that name its own stream of random numbers. reset with a seed makes the same numbers come out in the same order, which helps when testing or replaying an event. Sequences and reset need operator level 2.

Bedrock Edition

Bedrock has no /random. Use the scoreboard instead:

/scoreboard objectives add dice dummy
/scoreboard players random @p dice 1 6

The nearest player's dice score becomes a number from 1 to 6. Branch on it with execute if score as on Java.

When it does not work

Common questions

Check your command

The Command Error Doctor checks common syntax mistakes in your browser.