# Need help making random numbers

**URL:** https://forum.kirupa.com/t/need-help-making-random-numbers/186530
**Category:** Uncategorized
**Created:** [April 22, 2006, 12:32am UTC](https://forum.kirupa.com/t/need-help-making-random-numbers/186530 "2006-04-22T00:32:38Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![kurth](https://avatars.discourse-cdn.com/v4/letter/k/e0b2c6/32.png) [@kurth](https://forum.kirupa.com/u/kurth)
#### Post date: [April 22, 2006, 12:32am UTC](https://forum.kirupa.com/t/need-help-making-random-numbers/186530/1 "2006-04-22T00:32:38Z")

</div>

I’m new to flash and i need to(by clicking a button) generate numbers between 1 and 10. I’ve seen other postings to do similar things such as this, but where would i put the action script, on the button? And what would be the action script for my dilemma?  
If you could help me i’d really appreciate it!  
thanx

---

<div class="post-metadata">

### Author: ![flextnet](https://avatars.discourse-cdn.com/v4/letter/f/7ba0ec/32.png) [@flextnet](https://forum.kirupa.com/u/flextnet)
#### Post date: [April 22, 2006, 2:18am UTC](https://forum.kirupa.com/t/need-help-making-random-numbers/186530/2 "2006-04-22T02:18:28Z")

</div>

You could put it on the button… let’s say you want to display the random number in a text field called ‘myNum’ on the main timeline:

on (press)  
{  
\_root.myNum.text = Math.floor(Math.random() \* 10) + 1;  
}

---

<div class="post-metadata">

### Author: ![kurth](https://avatars.discourse-cdn.com/v4/letter/k/e0b2c6/32.png) [@kurth](https://forum.kirupa.com/u/kurth)
#### Post date: [April 25, 2006, 3:59am UTC](https://forum.kirupa.com/t/need-help-making-random-numbers/186530/3 "2006-04-25T03:59:02Z")

</div>

Thanx, i got it to work.

---

<div class="post-metadata">

### Author: ![MichaelxxOA](https://avatars.discourse-cdn.com/v4/letter/m/9dc877/32.png) [@MichaelxxOA](https://forum.kirupa.com/u/MichaelxxOA)
#### Post date: [April 25, 2006, 7:13am UTC](https://forum.kirupa.com/t/need-help-making-random-numbers/186530/4 "2006-04-25T07:13:44Z")

</div>

You could also put together a method that will return a random float within a given range…

```auto

trace( randomRange(1, 10) );

function randomRange( min:Number, max:Number ) : Number
{
   return (Math.random() * (max-min)) + min;
}

```

That should do it, you can also choose whether you want it rounded or not…

TakeCare  
\_Michael
