# Quick random question

**URL:** <https://forum.kirupa.com/t/quick-random-question/5754>\
**Category:** Uncategorized\
**Created:** [September 20, 2002, 9:24pm UTC](https://forum.kirupa.com/t/quick-random-question/5754 "2002-09-20T21:24:54Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![eilsoe](https://avatars.discourse-cdn.com/v4/letter/e/9fc348/32.png) [@eilsoe](https://forum.kirupa.com/u/eilsoe)\
**Post date:** [September 20, 2002, 9:24pm UTC](https://forum.kirupa.com/t/quick-random-question/5754/1 "2002-09-20T21:24:54Z")

</div>

i think I’ve got a hang on the random thing, although I’ve used random before in ie qbasic…

i think random(); gives a number between 0 and 1, and random(10); gives a number between 0 and 10, but what if i want a number between say 10 and 30?

---

<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 20, 2002, 9:29pm UTC](https://forum.kirupa.com/t/quick-random-question/5754/2 "2002-09-20T21:29:30Z")

</div>

random(20)+10;

---

<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 20, 2002, 9:31pm UTC](https://forum.kirupa.com/t/quick-random-question/5754/3 "2002-09-20T21:31:13Z")

</div>

of course… (stupid me)

Thanks ilyas… 🙂

---

<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 20, 2002, 9:40pm UTC](https://forum.kirupa.com/t/quick-random-question/5754/4 "2002-09-20T21:40:23Z")

</div>

I just found out why my randoms almost never worked… I’ve been using Math.random() instead of just random()…

---

<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 20, 2002, 9:48pm UTC](https://forum.kirupa.com/t/quick-random-question/5754/5 "2002-09-20T21:48:04Z")

</div>

They’re not the same, as you said, as they don’t return the same thing. Actually, it is better to use Math.random since random has been deprecated with Flash MX… which forces you to do things like

```auto
myRandomNumber=Math.round(Math.random()*100);

```

to get a number between 0 and 100.

pom :asian:

---

<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 20, 2002, 9:59pm UTC](https://forum.kirupa.com/t/quick-random-question/5754/6 "2002-09-20T21:59:40Z")

</div>

I saw this on the Macromedia website:

```auto

onClipEvent (enterFrame) {
	Math.randomBetween = function(a, b) {
		return (a+Math.floor(Math.random()*(b-a+1)));
	};
	num = Math.randomBetween(5, 10); // use the function
}

```

If you define Math.randomBetween as a function once, you can use it again in your movie just like

myrandomNumber = Math.randomBetween(4, 100);

---

<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 20, 2002, 10:04pm UTC](https://forum.kirupa.com/t/quick-random-question/5754/7 "2002-09-20T22:04:06Z")

</div>

?? No need the define the function onEnterFrame, is there??

---

<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 20, 2002, 10:07pm UTC](https://forum.kirupa.com/t/quick-random-question/5754/8 "2002-09-20T22:07:20Z")

</div>

No, that was for something else - No. it shouldn’t be in enterFrame - can put it in (load).

---

<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 20, 2002, 10:08pm UTC](https://forum.kirupa.com/t/quick-random-question/5754/9 "2002-09-20T22:08:14Z")

</div>

I don’t like the look of the CODE tag - I prefer the blue I was using… ![](http://flex.funkyolive.com/im/crash.gif)
