Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Adding a frame rate to random() function

  • Adding a frame rate to random() function

    Posted by Davis Lindsay on May 30, 2012 at 5:42 pm

    I’m using the random(12) function to power my animation.
    It’s working great, but I want to make it go slower.

    Without using wiggler how would I update values every 5 frames?

    I thought I could do something like my code below, but I think it needs refinement.

    t = Math.round(time*30)%5;

    if(t=0){
    r=random(12);
    }else{
    r=0;
    }

    Prepare for today and you’ll survive, prepare for tomorrow and you will thrive.

    Davis Lindsay replied 13 years, 11 months ago 2 Members · 2 Replies
  • 2 Replies
  • Darby Edelen

    May 30, 2012 at 6:17 pm

    Try this:


    t = Math.floor(timeToFrames(time) / 5);
    seedRandom(t + index, true);
    random(12);

    In this case the seedRandom() function is ‘timeless’ so that calls to random() won’t generate new values over time, but the seed that we’re providing to seedRandom() is based on a modified frame count. When the modified frame count updates every 5 frames it should generate a new seed for the random() function. I’m also adding the index of the layer to the seed so that if you have several layers they won’t all return the same ‘random’ value.

    Just checked this in CS6 and it works great, the “+ index” portion of the seed isn’t even necessary as I suppose each call to the seedRandom() function generates a different random progression (at least in CS6, I’ve left it just in case this is different in previous versions).

    Darby Edelen

  • Davis Lindsay

    May 30, 2012 at 10:48 pm

    Thanks Darby,

    This simple code works better than I imagined.

    Prepare for today and you’ll survive, prepare for tomorrow and you will thrive.

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