ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# Creating a random number grid that automatically positions x and position y.

FAQ   •   VIEW ALL Creating a random number grid that automatically positions x and position y. on Jun 24, 2019 at 7:09:33 am

Hi, I am trying to create a random number grid having the x position expressed by index*(pixel value that fills the grid horizontally). Then when the first column fills, the x position returns to 1st column but the y position goes down to a certain amount of pixels. I am able to get it to work for 2 columns and rows with a multi-condition statement, but I know that it could be written as an equation, but not sure how to do it in javascript. There's always 19 columns before it should repeat so I'm guessing something to do with a variable representing multiples of 19 so that y position would drop down every 20, but at a loss beyond that. Appreciate any help with this. Thanks, David

```x position code// if (index&lt;=19) { index*192 } else if (index>19 || index&lt;=38) { (index-19)*192 } else if (index>38 || index&lt;=57) { (index-38)*192 } else if (index>57 || index&lt;=76) { (index-57)*192 } else if (index>76 || index&lt;=95) { (index-76)*192 } else if (index>95 || index&lt;=114) { (index-95)*192 } y position code// if (index&lt;=19) { 144 } else if (index>19 || index&lt;=38) { 288 } else if (index>38 || index&lt;=57) { 432 } else if (index>57 || index&lt;=76) { 576 } else if (index>76 || index&lt;=95) { 720 } else if (index>95 || index&lt;=114) { 864 } random number code (which is working okay to generate a random number between 1 and 9// seedRandom(1,true); Math.round(random(1,9));```

 Return to posts index Re: Creating a random number grid that automatically positions x and position y.on Jun 24, 2019 at 8:50:58 am

```multiplier = 20; columnNumber = 5; xpos = (index-1)%columnNumber*multiplier; ypos = Math.ceil(index/columnNumber)*multiplier; [xpos,ypos]```

If you want different multiplier on columns/rows:

```columnMultiplier = 20; rowMultiplier = 25; columnNumber = 5; xpos = (index-1)%columnNumber*rowMultiplier; ypos = Math.ceil(index/columnNumber)*columnMultiplier ; [xpos,ypos]```

Andrei
My Envato portfolio.

 Return to posts index