Minecraft – How to make a Random Number Generator with vanilla redstone?

minecraft-java-editionminecraft-redstone

I'm working on a game for my Minecraft server that includes the element of chance.

The idea is that there are 6 buttons. One of them (randomly determined by redstone circuitry) results in wealth, prizes, etc. The other five result in doom.

When you enter the room the doors close initiating the game and beginning the primary circuit which selects which of the 6 buttons is the winning button. How to actually make the circuitry do this is my problem! I've got the door controls, win/lose circuits, and the reset circuit to prepare the room for the next player all worked out, but I'm stumped on how to make redstone do something random.

How can I use redstone to choose one of the 6 buttons to be active, randomly?

Best Answer

One of the most common ways to make a real random circuit is to create a very fast clock that quickly cycles through the possible outputs, which will stop as soon as a person pushes a button. If the circuit is fast enough, or hidden from them, then the exact moment they stop the circuit is sufficiently random to serve many applications.

This can be implemented in redstone using a 6-state ring counter that is constantly "ticked" by a clock circuit, with the clock stopped by the latched human input (which in this case, would be the same as your door-open button), so that when they push the button the ring counter stops changing and its output becomes your button-selection data.

Even better, but more complicated, would be to create a memory cell that "captures" the state of the ring counter when the human input button is pushed, and uses the memory cell as the activation data instead, so that the ring counter never has to be stopped from cycling. That would make the ring counter even less predictable, and make the randomness higher quality.