User Guide
random() 489
This statement determines whether the memory needed to display frames 100 to 125 is more
than the available memory, and, if it is, branches to the section using cast members that have
lower color depth:
-- Lingo syntax
if (_movie.ramNeeded(100, 125) > _system.freeBytes) then
_movie.go("8-bit")
end if
// JavaScript syntax
if (_movie.ramNeeded(100, 125) > _system.freeBytes) {
_movie.go("8-bit");
}
See also
freeBytes(), Movie
random()
Usage
-- Lingo syntax
random(integerExpression)
// JavaScript syntax
random(integerExpression);
Description
Top level function; returns a random integer in the range 1 to a specified value. This function can
be used to vary values in a movie, such as to vary the path through a game, assign random
numbers, or change the color or position of sprites.
To start a set of possible random numbers with a number other than 1, subtract the appropriate
amount from the
random() function. For example, the expression random(n + 1) - 1 uses a
range from 0 to the number
n.
Parameters
integerExpression
Required. Specifies the maximum value of the random number.
Example
This statement assigns random values to the variable diceRoll:
-- Lingo syntax
diceRoll = (random(6) + random(6))
// JavaScript syntax
var diceRoll = (random(6) + random(6));
This statement randomly changes the foreground color of sprite 10:
-- Lingo syntax
sprite(10).foreColor = (random(256) - 1)
// JavaScript syntax
sprite(10).foreColor = (random(256) - 1);