Monday, 12 September 2011

To generate Random Numbers in AS-3


To generate random numbers : here Math.floor returns the floor of the number or expression specified in the parameter val. The floor is the closest integer that is less than or equal to the specified number or expression.
And Math.random returns a pseudo-random number n, where 0 <= n < 1. To avoid 0 we are using +1 at the end.
     <fx:Script>
    <![CDATA[
    var randNum:Number=Math.floor(Math.random()*100)+1;
    txtRandNum.text=""+randNum;
    ]]>
    </fx:Script> 
    <mx:Text  id="txtRandNum"/>


No comments:

Post a Comment