ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# random frames without repeating

FAQ   •   VIEW ALL
 random frames without repeating on Dec 3, 2008 at 7:23:27 pm

Hi!
I've got a jpg footage and I want to change randomly the order in wich the images apears in the comp. I need to see every image without repeating it and also asign them diferent durations (I mean showing them about a random number betwen 25-40 frames each)
I've tried using Dan's answer to this post (http://forums.creativecow.net/readpost/227/10813) but I'm afraid it isn't the solution.
The problem is that it's my first time with After Effects expressions and I don't know how to do it. (And I even don't know if it can be done with expressions)
Thanks for your help and contratulations for this site and also for the podcast!
Pablo.

 Re: random frames without repeatingon Dec 3, 2008 at 11:02:41 pm

Assuming that your images are sequenced 1 per frame (either as an image sequence, or in a precomp), a time remapping expression like this should do what you want:

n = 100; // number of images
minDur = 25;
maxDur = 40;

seedRandom(index,true);
images = [];

for(i = 0; i < n; i++){
images[i] = i;
}

for (i = 0; i < n; i++){
idx = i + Math.floor(random(images.length - i));
temp = images[i];
images[i] = images[idx];
images[idx] = temp;
}

dur = 0;
f = -1;
while (time >= dur*thisComp.frameDuration && f < images.length - 1){
f++;
dur += Math.floor(random(minDur,maxDur+1));
}
images[f]*thisComp.frameDuration

You'll need to adjust the first parameter to match the number of images in your sequence.

Dan

 Re: random frames without repeatingon Dec 3, 2008 at 11:13:11 pm

Great! It's exactly what I wanted to do!
Thanks a lot!

 Re: random frames without repeatingon Jan 15, 2010 at 5:09:56 pm

I'm digging up an old one here...

Any idea why, when I try this in CS4, I get the following error?

After Effects warning: Expected: ;
Expression disabled.
Error occurred at line 9.

I know zilch about anything but the simplest expressions, but I tried randomly adding a ";" to line 9. Oddly enough, that didn't work ;)

 Re: random frames without repeatingon Oct 26, 2012 at 10:59:11 pm

This tutorial explains how to use Photoshop and After Effects CS6 to create looping image sequences and includes a useful frame randomizing expression. Check it out here...

http://benmarkus.wordpress.com/2012/08/09/working-with-image-sequences-in-p...

 Re: random frames without repeatingon Jun 20, 2017 at 8:24:08 pm

hello , why i got blank frames into my animation? i set the frames to right number of frames my comp has tks

```n = 81; // number of images minDur =06; maxDur = 12; seedRandom(index,true); images = []; for(i = 0; i &lt; n; i++){ images[i] = i; } for (i = 0; i &lt; n; i++){ idx = i + Math.floor(random(images.length - i)); temp = images[i]; images[i] = images[idx]; images[idx] = temp; } dur = 0; f = 1; while (time >= dur*thisComp.frameDuration && f &lt; images.length - 1){ f++; dur += Math.floor(random(minDur,maxDur+1)); } images[f]*thisComp.frameDuration```

 Re: random frames without repeatingon Jun 20, 2017 at 8:59:28 pm

Hard to say without seeing it.

Dan

 Re: random frames without repeatingon Mar 1, 2018 at 1:44:17 am

Hi,

I am creating a template for myself to use regularly. I have used this expression so that I have a random image sequence with the timings for each image linked to a slider, but how would I add a 'loopOut("cycle") to this so that my random sequence loops?

I can't use loopOut("cycle") on a precomp since the duration of the image sequence changes when I change the image duration or number of images!

Best,