Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Random frames without repeat

  • Random frames without repeat

    Posted by Kasper Werther on October 9, 2015 at 12:20 am

    I’ve been searching around for a few hours to get this done.
    I have a 12fps composition containing 132 unique frames. I want the composition to play the frames in random order, without repeating a frame.

    I found multiple scripts, of which the one from this thread came very close: https://forums.adobe.com/message/4577715

    fr = 12; // frame rate;

    numFrames = 132;

    seedRandom(index,true);

    seg = Math.floor(time*fr);

    f = Math.floor(random(numFrames));

    for (i = 0; i < seg; i++)

    f = (f + Math.floor(random(1,numFrames)))%numFrames;

    framesToTime(f);

    Only the thing is, I see frames being repeated a few times. I tried messing around a bit, but I can’t seem to get it right. What do I add to prevent this? (and where in the code)

    Ilya Sire replied 9 years, 5 months ago 3 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    October 9, 2015 at 5:14 am

    Do you mean that you want each fame to display once, and only once in the complete sequence of frames, or do you just need the same frame to not show twice in a row?

    Dan

  • Kasper Werther

    October 9, 2015 at 10:02 am

    I only want to display each frames once, and only once in the complete sequence of frames 🙂

  • Dan Ebberts

    October 9, 2015 at 5:29 pm

    I think this is close to what you’re looking for:


    numFrames = 132;
    a = [];
    seedRandom(index,true);
    for (i = 0; i < numFrames; i++)a.push(i);
    for (i = 0; i < numFrames; i++){
    idx = i + Math.floor(random(a.length - i));
    temp = a[i];
    a[i] = a[idx];
    a[idx] = temp;
    }
    idx = timeToFrames(time)%numFrames;
    framesToTime(a[idx])

    Dan

  • Kasper Werther

    October 9, 2015 at 7:43 pm

    It seems to work, I did not notice a repeated frame yet!
    Thank you, much appreciated!

  • Ilya Sire

    November 23, 2016 at 1:29 pm

    Hi Dan Ebberts,

    How to make this code always start with 0 frame and then next random?

    Sire

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