Problem
Need show a random number on the stage.
Solution
Generate a random numbers with Math.random
Detailed explanation
Please flash cs4 professional program and create new document with Flash File(ActionScript 3.0) type.

On COMPONENTS area find Button and TextArea components and move it to the Stage.
On TOOLS area find ‘Free Transform Tool’ and make width for components bigger, for example 300.



For TextArea component create instance name numberOutput, and for Button component create name generateNumberBtn.


Change label for button to ‘generate number again’.

Create new layer for actions.

On Layer2 write code:
var minNumber:uint=1;
var maxNumber:uint=48;
var numberRange:uint=maxNumber-minNumber;
var
randomNumber:Number=Math.ceil(Math.random()*numberRange)+minNumber;
trace("our random number = "+" "+ String(randomNumber));
numberOutput.text="our random number = "+" "+String(randomNumber);

After this you can test a movie. So now your number will be randomly appears on the stage.
So now we need add some code for button.
generateNumberBtn.addEventListener(MouseEvent.CLICK, buttonClick);
generateNumberBtn.useHandCursor=true;
function buttonClick(event:MouseEvent):void {
gotoAndPlay(1);
}

After cliking the button we will cause function buttonClick.
Now you need insert frame to bouth layers.

And add next code to ACTIONS area:
stop();
gotoAndStop(2);

After this you can test movie your file. And click to button again and again. And you will see how your number will be randomly change.

In attached files you can find pictures preview with red areas borders. They can help you to clear all steps. Also .fla file with ready project.
Source:
my_random_number
Thank you for reading.
