Math
425
random (Math.random method)
public static random() : Number
Returns a pseudo-random number n, where 0 <= n < 1. The number returned is a pseudo-
random number because it is not generated by a truly random natural phenomenon such as
radioactive decay.
Availability:
ActionScript 1.0; Flash Lite 2.0 - In Flash Player 4, the methods and properties
of the Math class are emulated using approximations and might not be as accurate as the non-
emulated math functions that Flash Player 5 supports.
Returns
Number
- A number.
Example
The following example outputs 100 random integers between 4 and 11 (inclusively):
function randRange(min:Number, max:Number):Number {
var randomNum:Number = Math.floor(Math.random() * (max - min + 1)) + min;
return randomNum;
}
for (var i = 0; i < 100; i++) {
var n:Number = randRange(4, 11)
trace(n);
}
round (Math.round method)
public static round(x:
Number
) : Number
Rounds the value of the parameter
x
up or down to the nearest integer and returns the value.
If parameter
x
is equidistant from its two nearest integers (that is, the number ends in .5), the
value is rounded up to the next higher integer.
Availability:
ActionScript 1.0; Flash Lite 2.0 - In Flash Player 4, the methods and properties
of the Math class are emulated using approximations and might not be as accurate as the non-
emulated math functions that Flash Player 5 supports.
Parameters
x
:
Number
- A number.
Returns
Number
- A number; an integer.
Summary of Contents for Flash Lite 2
Page 1: ...Flash Lite 2 x ActionScript Language Reference...
Page 22: ...22 Contents...
Page 244: ...244 ActionScript language elements...
Page 760: ...760 ActionScript classes...