# Random movement in defined area

**URL:** https://forum.kirupa.com/t/random-movement-in-defined-area/70414
**Category:** flash
**Created:** [November 13, 2004, 9:06pm UTC](https://forum.kirupa.com/t/random-movement-in-defined-area/70414 "2004-11-13T21:06:50Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Casenote](https://avatars.discourse-cdn.com/v4/letter/c/82dd89/32.png) [@Casenote](https://forum.kirupa.com/u/Casenote)
#### Post date: [November 13, 2004, 9:06pm UTC](https://forum.kirupa.com/t/random-movement-in-defined-area/70414/1 "2004-11-13T21:06:50Z")

</div>

I want to have about 15 verticle lines moving randomly along the X axis

Now I have modified the Kirupa random movement tutorial to this code:

```auto

onClipEvent (load){
//data you may want to change 
width = 300;
speed = Math.round(Math.random()*4)+1;
 //initial positions 
x = this._x=Math.random()*width;
x_new = Math.random()*width;
} 
onClipEvent (enterFrame) { 
//x movement 
if (x_new>this._x) { 
sign_x = 1;
 } else { 
sign_x = -1;
} 
dx = Math.abs(x_new-this._x);
 if ((dx>speed) || (dx<-speed)) { 
this._x += sign_x*speed;
 } else { 
x_new = Math.random()*width;
} 
} 

```

But I noticed the starting point of the verticle line is always in the same spot and is not confined to where I want it positioned…How would I define an exact stage for it be contained in?

Also it goes everywhere on the stage just not what is defined as the width in the begining of the code,

-Case
