Talk:Tutorials/Randomizers

Using redstone wire to activate multiple command blocks is outdated since 1.9 because you could use command chains instead and since 1.12, you could even use functions. To keep the concept generally applicable and overviewable, it would be better to list the commands and just give the option of using command blocks while still leaving space for better alternatives. Tick-Based randomizers have been used for a long time, but they don't work well for many cases and have obvious flaws. Commonly used methods in modern times would be scaling down UUIDs, using loot tables, using predicates or using pseudo-random algorithms like LCG.

There are libraries or native implementations for each of these methods. The libraries are, beyond others, featured by the RNG module of the Minecraft Phi data pack. Kappascopezz (talk) 00:23, 5 March 2020 (UTC)

New RNG Method
I was able to get a form of RNG working (tested in 1.16.3, but should work in any version with /scoreboard players operation) by using a combination of how the language C implements RNG (see here: https://stackoverflow.com/questions/4768180/rand-implementation ) and a bunch of scoreboard operations. All commands below should handle generating random numbers between 0 and 99.

Commands that need to be run once:

scoreboard objectives add rng_mult dummy

scoreboard objectives add rng_add dummy

scoreboard objectives add rng_div dummy

scoreboard objectives add rng_range dummy

scoreboard objectives add rand_helper dummy

scoreboard objectives add random dummy

scoreboard players set PLAYER rng_mult 1103515245

scoreboard players set PLAYER rng_add 12345

scoreboard players set PLAYER rng_div 65536

scoreboard players set PLAYER rand_helper 20

scoreboard players set PLAYER rng_range 100

NOTE: rng_range can be changed to any number, where that number-1 is the highest number that will be generated

Commands that should be run every tick (or when you need a random number, but the former is preferable):

execute as PLAYER run scoreboard players operation @s rand_helper *= @s rng_mult

execute as PLAYER run scoreboard players operation @s rand_helper += @s rng_add

execute as PLAYER run scoreboard players operation @s random = @s rand_helper

execute as PLAYER run scoreboard players operation @s random /= @s rng_div

execute as PLAYER run scoreboard players operation @s random %= @s rng_range

Advantages over other setups in JE (since BE already has /scoreboard players random):
 * Runs entirely in command blocks/functions, so no need for physical blocks to be placed, or for entities to keep loaded
 * Possibly easier to set up than the proposed alternatives on the wiki
 * Super easy to get a large variety of numbers from, just change the rng_range objective for what numbers you want

Limitations:


 * Requires commands
 * rng_range can't be higher than 65536.

If anyone finds this confusing, I'm happy to try to explain it better! Would love to see this added to the wiki, as it's a method of RNG that's been proven to work well (at least in the C programming language), and it's easy to scale to higher numbers without needing tons of commands and/or entities! As Kappascopezz had mentioned a few months ago, LCGs such as this are much more modern, and arguably better than other RNG implementations.

Apologies for any bad formatting, I haven't written on wikis much before, so I'm quite new to it!

Hammy275 (talk) 20:35, 13 October 2020 (UTC)

Do piston randomizers in bedrock edition still work?
If they do, please add them to the format, I would, but I can't make head or tail of the format!