Random (Math.random Method); Round (Math.round Method) - MACROMEDIA FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE Reference

Actionscript 2.0 language reference
Table of Contents

Advertisement

The
MovieClip.getNextHighestDepth()
7 or later. If your SWF file includes a version 2 component, use the version 2 components
DepthManager class instead of the

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 Player 5 - 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
- A number.
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
If parameter
is equidistant from its two nearest integers (that is, the number ends in .5), the
x
value is rounded up to the next higher integer.
Availability: ActionScript 1.0; Flash Player 5 - 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
- A number.
x:Number
method used in this example requires Flash Player
MovieClip.getNextHighestDepth()
up or down to the nearest integer and returns the value.
x
method.
Math
757

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE and is the answer not in the manual?

This manual is also suitable for:

Flash 8

Table of Contents

Save PDF