View Full Version : Randomization with No Repeats?
03-19-2011, 07:05 PM
I am working on an auto-scrolling level. A randomizer is hooked up to six different emitters that emit six different foreground pieces (the player must traverse these). Currently, these are emitted at random, but if possible I would like to have them emit WITHOUT emitting the same piece twice in a row. Is anyone aware of a method to accomplish this?
At first I thought I could do this by setting the randomizer to "Add and reset when full," but on this setting when the randomizer resets, the next wire simply stays on (the other ones just turn off). This means that no new signal is sent to the emitter, so it doesn't emit (they are set to "Emit once").
If anyone has a solution, it would be much appreciated!:)
03-19-2011, 07:18 PM
Set the randomizer's pattern to "add", then, it won't repeat any signal that's already been triggered unless you reset it.
03-19-2011, 09:31 PM
Thanks for the reply.
Two issues I see with this method:
1. There is still a chance to get two identical signals in a row. For instance signal 4 could be the last of the six activated, then the first after the randomizer is reset.
2. Is it possible to reset a randomizer set to "add"? I tried sending a negative value with a direction combiner, but this just adds another signal...
03-19-2011, 09:34 PM
The add setting can be reset by turning the randomizer off and then back on again, but you're right: there's the possibility that the last output of one randomizer cycle will be the first of the next cycle.
I assume your object need to emit at specific times since you're talking about a scrolling level. I think that I would try building a queue system between the randomizer and the emitters. So have the randomizer toggle on and trigger one of six ports on a selector. Once a selector port is active, it will toggle the randomizer off until whatever you use to control the sync tells it to emit, at which point it will turn the randomizer back on. The beauty of using a selector is that even if the randomizer picks the same port twice in a row, it won't actually make anything happen 'cuz the selector port is already active--any signals to turn on the already on port will be ignored and the randomizer will keep going until it triggers another port, which will trigger the the toggle again to turn off the randomizer and will put that port's signal into the emitter queue.
If that doesn't make any sense, I'll go ahead and build one and take a pic for you.
[Edit] I built it. Here's the simplified chip:
I omitted the repeated components to make the wires easier to see. You'll need a one-shot self-resetting counter for each of the selector's ports (6 all together) and they all need to be tied into the the OR gate at the bottom. Also, you'll need to place a circuit node on the sub-chip (what I like to call a circuit breaker) for each of the selector's ports and hook each of them to one of your emitters. The timer at the top controls the sync: set it to however long you need between each emitter firing, and set each emitter to "emit once".
The way it works is the timer switches the two port selector to its second state, which turns on the randomizer. The randomizer triggers one of the 6 port selector's states, which subsequently triggers a one-shot counter. The one-shot feeds into the OR gate which resets the two-port back to port one, turning off the randomizer. When the timer fills again, it turns on the circuit breaker chip for a single clock cycle--just long enough to tell the emitter to fire--and then turns it off again and turns the randomizer back on. If the randomizer chooses the same selector port that's already active, nothing happens, 'cuz it can't turn on something that's already on, so the randomizer stays on until it chooses another port.
03-19-2011, 11:40 PM
Thanks much for the detailed response! Just built a full version of the rig and it works perfectly. Screenshot helped simplify things too.
Sweet Sacktimus Prime btw, :P
Powered by vBulletin® Version 4.1.12 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.