rand()

Generates a random number.

With no parameters, it returns a random floating-point number between 0 and 1.

With one parameter, it returns a random integer in the range 0 to max.

With two parameters, it returns a random integer in the range min to max.

Syntax

rand()
rand(max)
rand(min, max)

Parameters

Parameter Type Description
max Number Upper bound (inclusive). Used with a single parameter. optional
min Number Lower bound (inclusive). optional
max Number Upper bound (inclusive). Must be greater than min. optional

Return Value

Examples

rand();       // random float between 0 and 1 
rand(10);     // random integer from 0 to 10
rand(5, 10);  // random integer from 5 to 10

See also

datetime