# Random movement within a grid

**URL:** <https://forum.kirupa.com/t/random-movement-within-a-grid/211647>\
**Category:** Uncategorized\
**Created:** [January 3, 2007, 10:08pm UTC](https://forum.kirupa.com/t/random-movement-within-a-grid/211647 "2007-01-03T22:08:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nb23](https://avatars.discourse-cdn.com/v4/letter/n/bbce88/32.png) [@nb23](https://forum.kirupa.com/u/nb23)\
**Post date:** [January 3, 2007, 10:08pm UTC](https://forum.kirupa.com/t/random-movement-within-a-grid/211647/1 "2007-01-03T22:08:31Z")

</div>

I’m trying to move a series of dots (mc used as linkage: “Dot”) within a frame to random targets, with the movement activated by onRollOver. This part I have working fine. The part I’m having difficulty with is getting the objects to have target coordinates to move randomly, except rounded to the nearest 12 pixels. Any ideas? Thanks in advance.

Here’s the relevant code:

```auto
minx = 120;
maxx = 450;
miny = 20;
maxy = 60;

function randx() {
    var x = minx+Math.round(Math.random()*(maxx-minx));
    return x;
}
function randy() {
    var y = miny+Math.round(Math.random()*(maxy-miny));
    return y;
}

```
