14

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?

8
  • 11
    Why was this closed? Asking how to randomly set one of 6 redstone lines active is entirely on-topic. Aug 8, 2013 at 17:00
  • 2
    I agree with @SevenSidedDie - given the other Minecraft redstone questions which get asked, this one seems totally on topic.
    – shanodin
    Aug 8, 2013 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. Aug 8, 2013 at 17:14
  • @SevenSidedDie whoops, sorry about that. Fixed it.
    – user28379
    Aug 8, 2013 at 17:21
  • This question is much better with the edit, worth reopening.
    – Resorath
    Aug 8, 2013 at 17:29

6 Answers 6

10

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.

4

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.

In your case, since you want to have six random outputs, you could put six unique items into a dropper or dispenser (such as six different shades of colored wool). When the player presses a button, the dropper will randomly throw out one of the items.

Then, you can use flowing water to carry the item over six hoppers. Each hopper should be completely full of the item that you want to detect, minus one. (So for example, have a hopper with 64-64-64-64-63 blue wool, another with red wool, etc.) You can detect which hopper collects the wool by using a comparator, which only outputs on maximum strength when a container is completely full1.

Once you know which hopper collected the item, you can use this random output for your desired purposes. The only cleanup necessary is to move that item from the hopper back into the dropper so that this system will be reusable. You could have another set of hoppers underneath the first set and temporarily enable them for one tick when the comparator is at full strength, so that they pull the item out again and put it back into the original dropper.

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

Have 2 sticky pistons "fighting" over a redstone block. 2 pistons facing each other with 3 blocks in between them, and a redstone block in the middle of the open space.power the pistons with a pulse at the same time and once the pulse ends, the pistons retract and there is a 1/2 chance that either piston gets the block. Put the output in between the redstone block and the pistons and if the left piston pulls the block towards it, the output will be left side.

1

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.

1
  • 2
    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. Sep 17, 2013 at 23:52
0

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.

1
  • This is a useful answer to a limited extent. Video linked within the answer needs to be summarized in the answer for it to be helpful with youtube blocked: link-only answers are bad. If diagrams and details are added and the unneccessary bits stripped to make a minimal example that would make it more useful.
    – aphid
    Oct 20, 2020 at 8:14
0

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.

Not the answer you're looking for? Browse other questions tagged .