Channel Icon

Crazy Ozz

Official Channel Website

Command Block

How to Generate Random Numbers and Random Events in Minecraft

Minecraft Java 1.21+ and 26+ – Random Value Command + Scoreboard System

Want to create random loot, chance systems, and random events in Minecraft? In this tutorial, you’ll learn how to generate random numbers using the scoreboard system and the random value command. This is perfect for minigames, custom maps, datapacks, and adventure mechanics where different outcomes happen every time.

Before we start generating random numbers and, as a result, random events, create this scoreboard (number)

scoreboard objectives add number dummy

If you want the random number to appear on the sidebar, use this command

scoreboard objectives setdisplay sidebar number

Now let's generate a random number from 1 to 10 for each player

execute as @a run execute store result score @s number run random value 1..10

And from that, trigger a random event if the number is 5 using the command below

execute as @a if score @s number matches 5 run

This last command must be placed in a Repeat command block set to Always Active

Add any command you want after run, but remember it will run infinitely

To prevent that, you can reset the score after it reaches the number you wanted and the command is executed

Or simply use a comparator with a piston and a redstone block in front, and remove the run command

Discover CastroTools

Looking for more online tools? CastroTools offers a JSON formatter, QR code generator, image and audio converters, password generator, calculators, and much more, all free and easy to use.

🚀 Explore CastroTools

Still have questions? Watch the video below