Predicate method: A special source of random in Minecraft
If you want to makehave a two-output randomizationsingle command to run on a certain chance or not, and want to use one of Minecraft's built-in randomization methods, try out predicates. Predicates are special condition files that are queried with an entity you select to see if the conditions of that entity match the predicate.
Luckily for our use, the predicates have a random_chance
condition, which means that the predicate will return a true condition with a customizable level of chance.
Here is what your predicate file will look like:
{
"condition": "minecraft:random_chance",
"chance": 0.1
}
chance
is a number you can customize from 0.0 to 1.0. The number denotes the chance of the condition to pass. 0.0 means it will never pass, and 1.0 means it will always pass.
You can query the predicate like this:
execute as @r if entity @s[predicate=<predicateName>] run ...
Creating different predicates and making a binary tree of them with different weights will allow you to make limitless possibilities for chances and randomness. However, it may not be worth it if you have too many possible outputs, and you may want to try a different way.