FORUMS: list search recent posts

# Time Remapping - Unique Random playback

FAQ   •   VIEW ALL
 Time Remapping - Unique Random playback on May 4, 2012 at 4:32:57 am

Hi there,

I have a comp with time-remapping enabled, and a script to change the way the playhead scrubs, so that it will play one second from a random location in the comp and then move to another random location.

What I would like to do is make it play the random location only once, so that I essentially have a movie clip the same length as the comp, and all of the content from that comp, expcept mixed up into a random order.

Here is the random code I'm currently using as a starting point:
```segDur = 1;// duration of each "segment" of random time minVal = inPoint; maxVal = outPoint - segDur; seed = Math.floor(time/segDur); segStart = seed*segDur; seedRandom(seed,true); startVal = random(minVal,maxVal); endVal = startVal + segDur; linear(time,segStart,segStart + segDur, startVal, endVal); ```

In other coding languages i've done similar things using an array and checking the scrubber against the times in the array, but i'm not sure how to do that in expressions, and also i think there is probably a more efficient way to do it.

Any help is greatly appreiated, cheers!
Tyler

 Re: Time Remapping - Unique Random playbackon May 4, 2012 at 8:33:51 am

This should let you divide the clip into n equal-length segments and play each segment once, in random order.

``` n = 10; // divide clip into 10 segments segDur = (outPoint - inPoint)/n; segs = []; for (i = 0; i < n; i++) segs[i] = i; seedRandom(index,true); for (i = 0; i < n; i++){ idx = i + Math.floor(random(segs.length - i)); temp = segs[i]; segs[i] = segs[idx]; segs[idx] = temp; } curSeg = Math.max(Math.min(Math.floor((time - inPoint)/segDur),n-1),0); t = (time - inPoint)%segDur; segs[curSeg]*segDur + t ```

Dan

 Re: Time Remapping - Unique Random playbackon May 6, 2012 at 7:48:01 pm

Thanks Dan, that worked perfectly.

You probably recognised the original code, it's from your motionscript site - lots of great resources on that site!

Cheers,
Tyler