Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Implementing random seed but maintaining several objects playing at the same time not just 1

  • Implementing random seed but maintaining several objects playing at the same time not just 1

    Posted by Wyclef Chron on December 10, 2012 at 8:25 pm

    Hey, wanting to use this code to make a composition of a star randomly appear on stage but it only works for 1 at a time. Wondering how I can tweak this to allow for 3, and at varying times not in sync. I could just have 3 different layers and change the holdTime but thought there might be a more logical approach. New to expressions.


    holdTime = 2; //time to hold each position (seconds)
    minVal = [0.2*thisComp.width, 0.2*thisComp.height];
    maxVal = [0.4*thisComp.width, 0.8*thisComp.height];

    seed = Math.floor(time/holdTime);
    seedRandom(seed,true);
    random(minVal,maxVal)

    Appreciate any help. Thanks.

    Darby Edelen replied 13 years, 6 months ago 2 Members · 3 Replies
  • 3 Replies
  • Darby Edelen

    December 11, 2012 at 4:54 am

    I believe you can just modify your seed slightly based on the layer index, something like:

    seed = Math.floor(time/holdTime) + index;

    Darby Edelen

  • Wyclef Chron

    December 12, 2012 at 10:17 pm

    hmmm… that didn’t seem to work.

  • Darby Edelen

    December 12, 2012 at 11:05 pm

    [wyclef chron] “hmmm… that didn’t seem to work.”

    Sorry, it seems I didn’t quite understand the problem. I’m still not quite sure the behavior you’d like to see but this should be closer:

    seedRandom(index, true);
    offset = random(0, 1);
    holdTime = 2;
    minVal = [0.2*thisComp.width, 0.2*thisComp.height];
    maxVal = [0.4*thisComp.width, 0.8*thisComp.height];
    seed = Math.floor((time + offset)/holdTime);
    seedRandom(seed,true);
    random(minVal,maxVal)

    Each layer will still hold for 2 seconds but the updates of the random values will be offset by up to 1 second from one another.

    Alternatively you can just generate a random number for the holdTime per layer:

    seedRandom(index, true);
    holdTime = random(1, 3);
    minVal = [0.2*thisComp.width, 0.2*thisComp.height];
    maxVal = [0.4*thisComp.width, 0.8*thisComp.height];
    seed = Math.floor(time/holdTime);
    seedRandom(seed,true);
    random(minVal,maxVal)

    Some layers will update more frequently than others with this method.

    Darby Edelen

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