# Change speed of random motion

**URL:** https://forum.kirupa.com/t/change-speed-of-random-motion/5174
**Category:** Uncategorized
**Created:** [September 3, 2002, 7:38pm UTC](https://forum.kirupa.com/t/change-speed-of-random-motion/5174 "2002-09-03T19:38:05Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Ryan](https://avatars.discourse-cdn.com/v4/letter/r/a8b319/32.png) [@Ryan](https://forum.kirupa.com/u/Ryan)
#### Post date: [September 3, 2002, 7:38pm UTC](https://forum.kirupa.com/t/change-speed-of-random-motion/5174/1 "2002-09-03T19:38:05Z")

</div>

i was wondering if it was possible to change the speed of the random motion. i was using Suprabeener’s AS for flash MX. thanks for any help.

=ryan=

---

<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: [September 3, 2002, 7:50pm UTC](https://forum.kirupa.com/t/change-speed-of-random-motion/5174/2 "2002-09-03T19:50:49Z")

</div>

i read over the AS and figured out what i was doing wrong, thanks anyway.

---

<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: [September 10, 2002, 10:24pm UTC](https://forum.kirupa.com/t/change-speed-of-random-motion/5174/3 "2002-09-10T22:24:05Z")

</div>

can you tell me what you did to get the speed increased?

---

<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: [September 10, 2002, 10:34pm UTC](https://forum.kirupa.com/t/change-speed-of-random-motion/5174/4 "2002-09-10T22:34:32Z")

</div>

look through the script for

```
 this.speed = Math.random()*4+2;

```

the “4” is the max speed, and the “2” is the min speed, and it will randomly pick a number between the 2 so if your script looked like this

```
    this.speed = Math.random()*80+1;  

```

it could go anywhere form extremely fadst to extremely slow, just play around with the numbers and see what you come up with, also yoiu may want to check out this script inside of all that too…

```
  	if (getTimer()-this.t&gt;1000) {

```

the “1000” is the time it sits between movements. the higher the number the longer it will sit still.

hope this helped you out.

=ryan=

---

<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: [September 11, 2002, 6:58am UTC](https://forum.kirupa.com/t/change-speed-of-random-motion/5174/5 "2002-09-11T06:58:39Z")

</div>

one thing you didnt include, and some people may need this info:  
Math.random()\*15+5 will return values between 5 & 15, BUT it will return a lot more than 10 different values, because MX will take it out to like 8 decimel places (ie 7.927001568 or something, I forget how many places exactly it goes to, but it is a bunch). In order to aviod this you can use Math.round() which will round using conventional methods. Or you can use Math.floor() which will always round down or Math.ceiling() which will always round up. Useful if you want random vales within a range but dont want to end up with a bunch that are only a few 0.0001 off of eachother. Just an FYI.

Peace

---

<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: [September 11, 2002, 7:36am UTC](https://forum.kirupa.com/t/change-speed-of-random-motion/5174/6 "2002-09-11T07:36:03Z")

</div>

> \*Originally posted by Ryall \*  
> \*_Math.random()15+5 will return values between 5 & 15_  
> Between 5 and 19.9999999999999999 actually 🙂

pom :asian:
