Minecraft Data Packs / Tool

Predicate-based prng for 20w46a+ (pseudorandom number generator)

  • check_circle Functions
  • check_circle Predicates
  • 968 views, 7 today
  • 43 downloads, 0 today
  • 7
  • 3
Zsigio avatar Zsigio
Level 45 : Master Strawberry
This pack is a simple random number generator utility function for Minecraft mapmakers and datapack creators that utilizes the "uniform distribution" option of predicates alongside the new ability to use scores as number providers to generate random numbers.

Non-predicate vs predicate

Scores in predicates brought the option to use Java's built-in pseudorandom number generator, which is considerably faster than previously possible methods including prng functions implemented in mcfunction (see mcskware's prng, I've been using his datapack), /spreadplayers based methods., etc.

Commands & usage

This pack provides two functions for generating prn-s, zt-rng:.get and zt-rng:.geta. The first is the recommended one, that includes all the bells and whistles of the pack, while the latter is just the bare-bones generator for performance sensitive situations.

You can set the range and scale using the zt-rng scoreboard:

  • .min: Lowest desired number (default: 0)
  • .max: Highest desired number (default: 1)
  • .scale: Output gets multiplied by this number (default: 1, can't be used with .geta)

After running zt-rng:.get or zt-rng:.geta, the following values get set

  • .out: A pseudorandom number between .min and .max (multiplied by .scale when not using .geta)
  • .success: Returns an error code (1-4) in case of an exception, otherwise 0 (unused with .geta)

Example usage

You can find an example use case in the function zt-rng:.debug. You can also test whether the pack is working or not by running /function zt-rng:.debug.

scoreboard players set .min zt-rng 1
scoreboard players set .max zt-rng 25
scoreboard players set .scale zt-rng 1

function zt-rng:.get

execute if score .success zt-rng matches 0 run tellraw @a ["A pseudo-random number between 5 and 25: ", {"score": {"objective": "zt-rng", "name": ".out"}}]


If the pack runs into an error with the given parameters, success will be set to an error number .out will be equal to zero, and you'll get a message notifying you of the error in the chat. You can disable or customize the messages in the file zt-tdc/data/zt-tdc/functions/conf/error.mcfunction.

  • errno. 1: Number of possible outputs exceeds the recursion limit. (Consider raising the value of the maxCommandChainLength gamerule or lower .max)
  • errno. 2: Maximum value is equal to or lower than minimum value.
  • errno. 3: Scoreboard overflow; part of the specified range exceeds the hardcoded upper limit of scoreboards (2147483647). (Consider lowering the scale factor)
  • errno. 4: scoreboard underflow; part of the specified range exceeds the hardcoded lower limit of scoreboards (-2147483648). (Consider lowering the scale factor)

Please note, that exceptions will only occur when .get is used, otherwise it might result in an uneven distribution, an out of bounds result, or an always 0 value if the given parameters are incorrect.

Install, update and uninstall

The pack has some version control utilities built in too. If you just need the bare-bones rng, and wish to get rid of all the bloat, you can delete the following files and folders: /data/zt-rng/functions/sys, /data/zt-rng/functions/conf, /data/zt-rng/functions/main/get-limit, load, remove, setup, /data/zt-rng/functions/.debug, .get, .remove and data/minecraft.

After installation when you first open/reload your world a confirmation message will appear in chat indicating successful installation. Upon installing a newer version of the pack the system will print another message reassuring you that the pack has been updated successfully.

If you wish to remove the datapack, run the uninstaller utility before deleting the file from the datapacks folder to avoid leftover scoreboards using the command /function zt-vtu:.remove[
CompatibilityMinecraft 1.17

Create an account or sign in to comment.

Planet Minecraft


© 2010 - 2021