# How can I make a Random Number Generator with vanilla 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?

-
Why was this closed? Asking how to randomly set one of 6 redstone lines active is entirely on-topic. – SevenSidedDie Aug 8 '13 at 17:00
I agree with @SevenSidedDie - given the other Minecraft redstone questions which get asked, this one seems totally on topic. – shanodin Aug 8 '13 at 17:11
It was hard to read before and very chatty. I've given it a thorough edit to laser-focus it on the RNG issue. – SevenSidedDie Aug 8 '13 at 17:14
@SevenSidedDie whoops, sorry about that. Fixed it. – Jeffrey Lin Aug 8 '13 at 17:21
This question is much better with the edit, worth reopening. – Resorath Aug 8 '13 at 17:29

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.

-

Random circuits can be made by putting different items into a dispenser and launching one out. After you determine which one is dispensed, you can reload it into the dispenser.

-
This is an interesting idea, but plenty of room for expansion to make this answer better. – Resorath Aug 8 '13 at 17:07
@Resorath Okay. I'll probably edit in more content soon. – Timtech Aug 14 '13 at 22:38

You can also use pig spawners to make it random. You could put a pressure plate under each spawner and, whenever a pig hits a pressure plate, that would be the button that is good while the rest would be bad until another pig spawns and hits another pressure plate.

If you don't know how to get pig spawners, since you can't even obtain them in creative mode, all you have to do is use cheats to spawn them in.

If you dont know the ID number of pig spawners, just go to this website: Minecraft ID List. Oh, and by the the way, you will have to put grass next to the spawners since pigs can only spawn on grass.

-
Trouble with pig spawners is that the distance at which the pig spawns is random but skewed to nearer the spawner, making it hard to use for randomisation. And then you have to deal with the times more than one pig spawns at once, and then how to get rid of the pig. – SevenSidedDie Sep 17 '13 at 23:52

My favorite implementation is using Dragnoz's approach here:

I do recommend modifying his design a bit, though. With all of the command blocks located on the same vertical plane, they will activate each other adjacently. The pressure plates have the same problem. So for my implementation, I stagger my command blocks/pressure plates vertically so that they do not activate surrounding blocks. Ill show a diagram I suppose:

``````_ => Pressure Plate
O => Command Block

_ _ _ _
O O O O
_ _ _
O O O
``````

This way, neither the pressure plate, nor the activated command block can erroneously activate surrounding command blocks.

## Edit

I just realized that Dragnoz has placed an intermediate lay between his pressure plate layer and command block layer. I somehow missed this while implementing the design for myself, but does actually appear to be more efficient than my suggested method. I will leave my solution for completeness, however.

-

execute @r[type=ArmorStand] ~ ~2 ~ setblock redstone_block

Just have the redstone under the Armor stand. NOTE:If you have more than one armor stand, just give the random ones custom names, then test for this:execute @r[type=ArmorStand,CustomName=] ~ ~2 ~ setblock ~ ~-2 ~ redstone_block

Oh, also, change the coordinates to wherever the armor stand is.

-