Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Storing Random Numbers to Variables to Calculate Percent of Change

  • Storing Random Numbers to Variables to Calculate Percent of Change

    Posted by Mike Phillips on October 7, 2019 at 3:01 pm

    I have a random number generator with a range from 800,000 to 900,000 linked to a text layer and it changes every second. I want to know is there a way of storing and holding previous values to a variable? Example: Lets say at second 1 the value of the text layer is 800,000 and on second 2 the value changes to 900,000. I want to store the first seconds value to a variable so I can calculate the percent of change.

    Mike Phillips replied 6 years, 10 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    October 7, 2019 at 4:03 pm

    Expressions have no memory, so variables don’t survive from one frame to the next. As a workaround, by manipulating the random number seed, you can recalculate the previous random number and use that to get the difference between the current and previous values. Something like this:

    period = 1; // duration of each random number
    seed = Math.floor(time/period);
    seedRandom(seed,true);
    nCur = random (800000,900000);
    seedRandom(seed-1,true);
    nPrev = random (800000,900000);
    diff = nCur – nPrev

    Dan

  • Mike Phillips

    October 7, 2019 at 4:06 pm

    Thank you will give this a try.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy