ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Random Number

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Scott McGee
Random Number
on Aug 29, 2017 at 8:56:56 am

I understand that there is no true, valueattime random expression.

But I need someway, not necessarily if I click purge, but certainly different each day.

I have random(1,6), this can't change, but I need to think of a way to change the number each day. I've seen some attempts at using Date(0), but that's to pull just a random number without worrying about the final number.

Can anyone think of a way to create an expression that will change it's value of the first frame using Date(0) to select a number between 1 and 6.


Return to posts index

Andrei Popa
Re: Random Number
on Aug 29, 2017 at 11:32:09 am

Maybe something like
seedRandom(Date(0).split(" ")[2])
random(1,6)

where you use the day as the seedRandom.

Andrei


Return to posts index

Scott McGee
Re: Random Number
on Aug 29, 2017 at 2:05:03 pm

That actually works quite nicely. Below is a few alterations, but if you know of a way so it doesn't repeat the same number twice. I've tried a few things, but I've just resorted to what I've done below...Although I'd like to incorporate getMonth, so I can create a A*B or A+B so it'll be different every day without repeating the same pattern each month...But unfortunately it fired back a lot of repeats and I can't change all of them. So if there is a way to change a repeated number that would be cool...Otherwise I am very happy with this.

Just because I want numbers 1-6, for some unknown reason it didn't select 1 often and never selected 6. So i've changed it to

D = Math.round(random(0,7));

if(D == 0) 1
else if (D == 7) 6
else
D;

Just to be sure...I went through the course of 1-31 using a slider, it picked the same number in a row twice, so I've include that if the

seedRandom(Date(0).split(" ")[2]) equals those two day, it just picks another number....

A = Date(0).split(" ")[2];

if (A == 5) A = 33
else if (A ==26) A = 34
else
A;

seedRandom(A,true);

D = Math.round(random(0,7));

if(D == 0) 1
else if (D == 7) 6
else
D;


So thank you.


Return to posts index


Andrei Popa
Re: Random Number
on Aug 29, 2017 at 8:38:25 pm

The only way i can think of to make the seedRandom() parameter to go from 1 to 365(so you don't have the same seed twice in a year) would be a not-so-elegant switch function in which we take all the moths and make the B equal to all the days before that month.
switch(Date(0).split(" ")[1]){
case "Jan":
B = 0;
break;
case "Feb":
B = 31;
break;
case "Mar":
B = 59;
break;
case "Apr":
B = 90;
break;
case "May":
B = 120;
break;
case "Jun":
B = 151;
break;
case "Jul":
B =181 ;
break;
case "Aug":
B = 212;
break;
case "Sep":
B = 243;
break;
case "Oct":
B = 273;
break;
case "Nov":
B = 304;
break;
case "Dec":
B = 334;
break;
}
A = Date(0).split(" ")[2]+B;
//then the rest of your code
I don't have AE installed on my laptop right now so i could not test this at at all. I hope it works.

Andrei


Return to posts index

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