random (JavaScript)

Generates a pseudorandom number greater than or equal to 0.0 and less than 1.0.

Defined in

Math (JavaScript)

Syntax

random() : double
Return value Description
double A random number in the range 0.0 (inclusive) through 1.0 (exclusive).

Usage

The first call to this method creates a new pseudorandom-number generator with a 48-bit seed based on the current time, as if creating an object with:
new java.util.Random()

Subsequent calls generate pseudorandom numbers with (approximately) uniform distribution.

Examples

This is the value formula for a list box. It creates a list of 10 items with random integers in the range 0-100.
var a = new Array();
for(var i=0; i<10; i++) {
	var n = Math.round(Math.random() * 100);
	a.push(n.toString());
}
return a