ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

After effects expression that draws a random number that is limited and decreasing

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Luka Dekleva
After effects expression that draws a random number that is limited and decreasing
on Sep 28, 2017 at 7:19:24 am

Hello,

I need to generate a random number, that is displayed as text on the screen. I need the number to be limited with a min and max value. The number needs to be limited to one decimal place, and the value needs to be decreasing. I need to generate 15 such numbers and they need to change every second.

I got as far as generating a random value within a limit that refreshes every second. I also got it limited to one decimal place.

Can someone help me with the decreasing of the value.

This is what i got now:

seedRandom(Math.floor(time), timeless = true);
random(125,115).toFixed(1)


Return to posts index

Dan Ebberts
Re: After effects expression that draws a random number that is limited and decreasing
on Sep 28, 2017 at 3:26:37 pm

Try this:

a = [];
seedRandom(index,true);
for (i = 0; i < 15; i++) a.push(random(115,125));
a.sort();
idx = Math.min(Math.floor(time),14);
a[14-idx].toFixed(1)


Dan



Return to posts index

Luka Dekleva
Re: After effects expression that draws a random number that is limited and decreasing
on Sep 29, 2017 at 11:43:26 am

Thank you Dan, it does just what i described. However when I set the min value to a two digit number like 90. It starts to behave different. After a few changes the number jumps to a higher value.

For instance

a = [];
seedRandom(index,true);
for (i = 0; i <15; i++) a.push(random(90,105));
a.sort();
idx = Math.min(Math.floor(time),14);
a[14-idx].toFixed(1)

Also with this expression the value starts below 100, no matter how high I set the max value.

Any idea why this is?


Return to posts index


Dan Ebberts
Re: After effects expression that draws a random number that is limited and decreasing
on Sep 29, 2017 at 9:30:08 pm

Sorry, I used the wrong sort(). Try this:

a = [];
seedRandom(index,true);
for (i = 0; i <15; i++) a.push(random(90,105));
a.sort(function(a, b){return a - b});
idx = Math.min(Math.floor(time),14);
a[14-idx].toFixed(1)

Dan



Return to posts index

Luka Dekleva
Re: After effects expression that draws a random number that is limited and decreasing
on Sep 30, 2017 at 5:14:42 am

Dan this is wonderful, thank you very much!
This expression also makes it easy to reverse and get a random increasing value. By changing a - b to b - a.

Luka


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]