# Random moving line

**URL:** https://forum.kirupa.com/t/random-moving-line/20492
**Category:** Uncategorized
**Created:** [May 9, 2003, 4:20am UTC](https://forum.kirupa.com/t/random-moving-line/20492 "2003-05-09T04:20:20Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![jonnooe](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jonnooe](https://forum.kirupa.com/u/jonnooe)
#### Post date: [May 9, 2003, 4:20am UTC](https://forum.kirupa.com/t/random-moving-line/20492/1 "2003-05-09T04:20:20Z")

</div>

im trying to create a random moving line along the x-coordinate that with each cycle will move for a random distance at a random speed. i can generate the ranom distance and speed just fine, but i cant get the speed to apply the movement for then length of the distance. i have tried using a for loop:

```auto
for(i = 0; i < distance/speed; i++)

```

but that creates an extremely fast and rough movement. i need a slow and smooth movement.  
any help would be greatly appreciated. here is my code:

```auto

onClipEvent (enterFrame) {
	speed = -20 + math.random() * (20 + 20);
	distance = 50 + math.random() * (300 - 50);
	for(i = 0; i < distance/speed; i++){
		_x += speed;
	}
}

```

---

<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 9, 2003, 4:32am UTC](https://forum.kirupa.com/t/random-moving-line/20492/2 "2003-05-09T04:32:11Z")

</div>

Flash 5: [http://www.kirupa.com/developer/actionscript/random.htm](http://www.kirupa.com/developer/actionscript/random.htm)

FLash MX: [http://www.kirupa.com/developer/mx/random\_motionMX.htm](http://www.kirupa.com/developer/mx/random_motionMX.htm)

This is not excatly what you are looking for but it might help you in accomplishing what you want. 🙂

---

<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 9, 2003, 5:14am UTC](https://forum.kirupa.com/t/random-moving-line/20492/3 "2003-05-09T05:14:49Z")

</div>

yea that isnt exactly what im looking for but in a sense it is i guess. what is want is  
[http://www.illusionnewmedia.com/INM\_Journey.html](http://www.illusionnewmedia.com/INM_Journey.html) then go to profile and you will see the lines moving up and down. i want something like that but horizontal. i think that the randommovement tutorial might have what i need, but im having a little trouble breaking it down and pinpointing the bit of code.

---

<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 11, 2003, 4:59am UTC](https://forum.kirupa.com/t/random-moving-line/20492/4 "2003-05-11T04:59:36Z")

</div>

hope this helps… i commented it… the code is all within the MCs themselves which are the vertical bars on the stage

---

<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 11, 2003, 6:28am UTC](https://forum.kirupa.com/t/random-moving-line/20492/5 "2003-05-11T06:28:45Z")

</div>

yes that did help me, thanks
