-
How to make random generator not repeat twice the same number ?
Hello there,
I know this is a common issue, but I can’t find a definitive answer to it. The closest I got was this thread
https://forums.creativecow.net/readpost/227/16179
where Dan states :“With After Effects, the issue is that an expression can’t directly control anything except the property to which it is applied. One thing you can do though is apply a slider control to one of the layers (let’s say the first one) and apply an expression to that which “publishes” the index of the layer that should currently be visible. The espression might look like this:
holdTime = .5;
n = 4;
segment = Math.floor(time/holdTime);
seedRandom(segment,true);
Math.floor(random(n)) + 1;This provides a random number from 1 to 4 that gets recalculated every half second. It gets more complicated if you need to make sure the same number doesn’t repeat twice in a row or if you want the hold times to vary.
Then you would apply an expression like this to each layer’s opacity property:
idx = thisComp.layer(1).effect(“Slider Control”)(“Slider”);
if (idx == index) 100 else 0″Unless I didn’t get it, I still don’t see how to make the generator not repeat itself. I understand I have to add some code to the first segment, but how ?