# Random 'y' movement

**URL:** <https://forum.kirupa.com/t/random-y-movement/20403>\
**Category:** Uncategorized\
**Created:** [May 8, 2003, 10:04am UTC](https://forum.kirupa.com/t/random-y-movement/20403 "2003-05-08T10:04:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![suha](https://avatars.discourse-cdn.com/v4/letter/s/8dc957/32.png) [@suha](https://forum.kirupa.com/u/suha)\
**Post date:** [May 8, 2003, 10:04am UTC](https://forum.kirupa.com/t/random-y-movement/20403/1 "2003-05-08T10:04:07Z")

</div>

i’ve applied the following script to a movieclip to change its ‘y’ coordinate randomly at run time and it works fine but i’m also trying to control the maximum ‘top’ and maximum bottom ‘y’ movement for which the value should be: top = 40 and bottom = 400. so it only displays randomly between 40 to 400 ‘y’ coordinate. could you tell me how can i implement this in the following script?

* * *

onClipEvent (enterFrame) {

\_x -= 4;  
if (\_x\<=-2247) {  
\_y = Math.random()\*300;  
\_x = 1024;  
}  
}

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 8, 2003, 10:07am UTC](https://forum.kirupa.com/t/random-y-movement/20403/2 "2003-05-08T10:07:48Z")

</div>

welcome, suha. =)

```auto
_y = 40+Math.random()*(400-40);

```

😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 8, 2003, 10:40am UTC](https://forum.kirupa.com/t/random-y-movement/20403/3 "2003-05-08T10:40:43Z")

</div>

working fine. cheers. much appreciated.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 8, 2003, 10:42am UTC](https://forum.kirupa.com/t/random-y-movement/20403/4 "2003-05-08T10:42:17Z")

</div>

de nada. 😛 =)
