ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# Generate new random number on each "marker" and hold until next marker

FAQ   •   VIEW ALL
 Generate new random number on each "marker" and hold until next marker on Mar 17, 2020 at 1:17:26 pm

Hello all,
As probably 99,99% of all AE users, this forum has tremendously helped me over the years... And I'm usually pretty good at piecing together a couple of expressions to make it work for me, but I am now struggling with this.

I need an expression that will generate a random number on each marker. Hold that number until the next marker and then generate another number, and so forth.
The random number should be between 2 and how many layers I have in the comp.

If you are wondering, I am trying to do an effect similar to what is described here, but instead of the layers flashing randomly, I want to be able to control every time a different layer is randomly displayed.

Thank you a lot !
Damien

 Re: Generate new random number on each "marker" and hold until next markeron Mar 17, 2020 at 2:26:58 pm

Probably something close to this:

``` m = marker; n = 0; if (m.numKeys > 0){ n = m.nearestKey(time).index; if (time < m.key(n).time) n--; } seedRandom(n,true); Math.floor(random(1,thisComp.numLayers))+1 ```

Dan

 Re: Generate new random number on each "marker" and hold until next markeron Mar 17, 2020 at 2:49:27 pm

Thank you a lot !

It's obviously simple, but my brain is not a coding one, so besides frankenstein-ing other expressions, I don't have the inside logic yet... But seeing this, looks obvious.

Thank you, again.

Damien

 Re: Generate new random number on each "marker" and hold until next markeron Mar 18, 2020 at 2:07:30 pm

If I may, something would make all of this even better...

Could the expression return the "comment" of the marker, if there is one ? (I would then comment the marker as a number depending on which layer I want to see).

And else (meaning, if there is no comment) then do the random number, as in the expression you wrote ?

Thanks again !
Damien

 Re: Generate new random number on each "marker" and hold until next markeron Mar 18, 2020 at 3:28:32 pm

Ok, and following my previous post... is there also an "easy" way for the randomly generated number to never be twice in the row the same...?

Please don't hesitate to tell me if my last requests are too complicated... I'm very aware of the time all this takes, and don't want to feel like I'm just fishing for shortcuts...

Thanks a lot.
Damien

 Re: Generate new random number on each "marker" and hold until next markeron Mar 23, 2020 at 4:19:07 pm

Hi all,

If anyone ever comes across this post and wonders, I have found a workaround to the if/else expression...

So I have all my layers of videos, with a Control Null, just like in this post.

I have Dan's expression on the Control layer which allows me to place markers wherever I want a cut to a random layer to occur... And then I duplicated this whole comp, named it something else, with the expression below on the control Layer.

I then import this new comp to the other one, and I use it as a control layer itself, where I put markers with names like "3" or "5", etc... whenever I'm not happy with the layer that was selected by the random one.

All this is perhaps confusing if you don't know what I'm talking about, but hopefully if someone is trying to achieve this exact effect he will be able to work it through !

Thanks again, and stay safe (and home !).
Damien

```m = comp("CompNameWithRandomGeneratedCuts").layer("CompNameWhereYouWantToPutTheMarkers").marker; txt = ""; if (m.numKeys > 0){ n = m.nearestKey(time).index; if (time &lt; m.key(n).time) n--; if (n > 0) txt = m.key(n).comment; } txt```