# gotoandStop at a random number between a certian range

**URL:** <https://forum.kirupa.com/t/gotoandstop-at-a-random-number-between-a-certian-range/527572>\
**Category:** flash\
**Created:** [February 7, 2015, 5:33pm UTC](https://forum.kirupa.com/t/gotoandstop-at-a-random-number-between-a-certian-range/527572 "2015-02-07T17:33:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![theKennedy](https://avatars.discourse-cdn.com/v4/letter/t/e9bcb4/32.png) [@theKennedy](https://forum.kirupa.com/u/theKennedy)\
**Post date:** [February 7, 2015, 5:33pm UTC](https://forum.kirupa.com/t/gotoandstop-at-a-random-number-between-a-certian-range/527572/1 "2015-02-07T17:33:18Z")

</div>

i have tried several solution i have found for this problem but cant get any to work.  
i want a button in flash as3 to goto and stop at a random frame. (ie a frame between 20 and 30)  
below is what i thought would work, although i have tried other code this is what makes most sense to me;

stop();

/\*random number bit  
\*/

function randomNumber(low:Number=20, high:Number=30):Number

{  
return Math.floor(Math.random() \* (1+high-low)) + low;  
}

/\*THE BUTTON ACTION  
\*/

movieClip\_1.addEventListener(MouseEvent.CLICK, fl\_ClickToGoToAndStopAtFrame);

function fl\_ClickToGoToAndStopAtFrame(event:MouseEvent):void  
{  
gotoAndStop(randomNumber);  
}

please help  
cheers

---

<div class="post-metadata">

**Author:** ![tbo](https://avatars.discourse-cdn.com/v4/letter/t/7feea3/32.png) [@tbo](https://forum.kirupa.com/u/tbo)\
**Post date:** [February 7, 2015, 6:15pm UTC](https://forum.kirupa.com/t/gotoandstop-at-a-random-number-between-a-certian-range/527572/2 "2015-02-07T18:15:11Z")

</div>

you were close, try  
**gotoAndStop(randomNumber());**

---

<div class="post-metadata">

**Author:** ![theKennedy](https://avatars.discourse-cdn.com/v4/letter/t/e9bcb4/32.png) [@theKennedy](https://forum.kirupa.com/u/theKennedy)\
**Post date:** [February 7, 2015, 8:46pm UTC](https://forum.kirupa.com/t/gotoandstop-at-a-random-number-between-a-certian-range/527572/3 "2015-02-07T20:46:22Z")

</div>

Brilliant  
Thanks tbo  
It worked straight away
