# Math.random()

**URL:** https://forum.kirupa.com/t/math-random/264404
**Category:** Uncategorized
**Created:** [June 25, 2008, 8:18pm UTC](https://forum.kirupa.com/t/math-random/264404 "2008-06-25T20:18:18Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![RebuiltJorge](https://avatars.discourse-cdn.com/v4/letter/r/94ad74/32.png) [@RebuiltJorge](https://forum.kirupa.com/u/RebuiltJorge)
#### Post date: [June 25, 2008, 8:18pm UTC](https://forum.kirupa.com/t/math-random/264404/1 "2008-06-25T20:18:18Z")

</div>

besides Math.random(), is there another way to specify a range of numbers, say between 0-100,

---

<div class="post-metadata">

### Author: ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)
#### Post date: [June 25, 2008, 8:37pm UTC](https://forum.kirupa.com/t/math-random/264404/2 "2008-06-25T20:37:22Z")

</div>

A random range of numbers, or any range of numbers?

---

<div class="post-metadata">

### Author: ![RebuiltJorge](https://avatars.discourse-cdn.com/v4/letter/r/94ad74/32.png) [@RebuiltJorge](https://forum.kirupa.com/u/RebuiltJorge)
#### Post date: [June 25, 2008, 8:41pm UTC](https://forum.kirupa.com/t/math-random/264404/3 "2008-06-25T20:41:40Z")

</div>

any range of number, it would all depend on the situation, for example, say i want to get a random number between -50 and 300, is there some other way to do get that number without using Math.random?

---

<div class="post-metadata">

### Author: ![Gundark](https://avatars.discourse-cdn.com/v4/letter/g/df705f/32.png) [@Gundark](https://forum.kirupa.com/u/Gundark)
#### Post date: [June 25, 2008, 9:16pm UTC](https://forum.kirupa.com/t/math-random/264404/4 "2008-06-25T21:16:36Z")

</div>

Not unless you build your own random number generator. I haven’t heard of anybody who has built one for Actionscript (of course I haven’t been looking).

If you want a random range using Math.random you can just use this function:

```auto

//Returns a random number between the two given numbers
function randRange(minNum:Number, maxNum:Number):Number 
{
	return (int(Math.random()*(maxNum-minNum+1))+minNum);
}

```

---

<div class="post-metadata">

### Author: ![Iamthejuggler](https://avatars.discourse-cdn.com/v4/letter/i/ecc23a/32.png) [@Iamthejuggler](https://forum.kirupa.com/u/Iamthejuggler)
#### Post date: [June 25, 2008, 9:18pm UTC](https://forum.kirupa.com/t/math-random/264404/5 "2008-06-25T21:18:27Z")

</div>

No. not that i know of. Just make a custom function that take the top and bottom parameters, for example:

public function rand(v1:Number, v2:Number):Number  
{  
var range = v2-v1;  
var result = v1+Math.random()\*range;  
return result;  
}

edit: ■■■■ you gundark!

---

<div class="post-metadata">

### Author: ![RebuiltJorge](https://avatars.discourse-cdn.com/v4/letter/r/94ad74/32.png) [@RebuiltJorge](https://forum.kirupa.com/u/RebuiltJorge)
#### Post date: [June 25, 2008, 11:38pm UTC](https://forum.kirupa.com/t/math-random/264404/6 "2008-06-25T23:38:20Z")

</div>

ok thanks
