Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Simple Postion Random Expression

  • Simple Postion Random Expression

    Posted by Avrohom Kohn on December 30, 2008 at 8:21 pm

    I know this is a silly question, but I couldn’t find the answer. I need to add a random position value (static) to a 3D layer, but I only want to randomize the x & z values, and I also want to limit where it goes. For example, I want a random z value between 0 and 1500, etc. & The same for the x…

    Thanks.

    Shawn Baden replied 8 years, 4 months ago 4 Members · 15 Replies
  • 15 Replies
  • Dan Ebberts

    December 30, 2008 at 8:50 pm

    Something like this:

    seedRandom(index,true);
    x = random(0,1500);
    z = random(0,1500);
    [x,value[1],z]

    Dan

  • Avrohom Kohn

    December 30, 2008 at 9:13 pm

    Thanks. That works. Could you just explain what this is for:

    seedRandom(index,true);

    Why couldn’t I just put in everything after that? I’m just trying to learn expressions and not just copy and paste every time.

    Thanks.

    Avrohom

  • Avrohom Kohn

    December 30, 2008 at 9:14 pm

    And one more thing:

    Every time I duplicate the layer, even the original randomizes again. Why doesn’t it stay at the position it already chose.

    thanks.

    Avrohom

  • Dan Ebberts

    December 30, 2008 at 9:28 pm

    Try it – you can’t break anything. 🙂

    What will happen is that the random position will change on every frame. seedRandom(seed,true) causes the same random numbers to be generated on each frame.

    Dan

  • Dan Ebberts

    December 30, 2008 at 9:31 pm

    Try using a constant for the seed rather than the layer index, like this:

    seedRandom(1,true);

    Dan

  • Avrohom Kohn

    December 30, 2008 at 9:35 pm

    Ok. I was playing around with it. The problem is, the layers seem to be staying close to each other. I have 2 layers, they’re nicely spaced. When I duplicate layer 2, both layer 3 and layer 2 are rerandomized, and mose times they stick dangerously close to each other and sometimes close to the first layer as well. Is there a way to control the amount of randomness?

    Avrohom

  • Avrohom Kohn

    December 30, 2008 at 9:39 pm

    This last thing you mentioned (seedRandom(1,true); ) works much better. I didn’t see it before. Sorry.

    I was playing around with different numbers instead of 1. 10 gives me better results. Could you just explain what it’s doing (what’s the random index of the layer, and what’s this number telling it)?

    Thanks.

    Avrohom

  • Dan Ebberts

    December 30, 2008 at 9:57 pm

    The seed value of SeedRandom() just sets the starting point for the sequence of random numbers that get generated in the expression. You can stick any number you want in there to get different results. index is just the layer number (the index of the top layer is 1, etc.) and it’s just a convenient thing to use as a seed because it’s different for each layer. However, as you’ve seen, using the same seed for each layer generates different results for each layer anyway.

    Dan

  • Tom Granberg

    May 14, 2010 at 4:24 pm

    Is there a way to force the random numbers to certain increments?
    Let’s say, always pick numbers that are 10 apart.
    So you end up with position changes that looks random but in a pre-defined grid increments?

    Thanks.

  • Dan Ebberts

    May 14, 2010 at 4:41 pm

    Sure – something like this should work (not tested):

    numberOfXPositions = 40;
    numberOfYPositions = 30;
    disctanceApart = 10;
    x = Math.floor(random(numberOfXPositions))*distanceApart;
    y = Math.floor(random(numberOfYPositions))*distanceApart;
    [x,y]

Page 1 of 2

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