Name

random() — NN 2 IE J1 ECMA 1

Synopsis

Returns a random number between and 1. To calculate a random integer between zero and another maximum value, use the formula:

Math.round(Math.random() * n)

where n is the top integer of the acceptable range. To calculate a random integer between a range starting with a number other than zero, use the formula:

Math.round(Math.random() * n) + m

where m is the lowest integer of the acceptable range and n+m equals the maximum value of the range. Note that the Math.random() method does not work in the Windows and Macintosh versions of Navigator 2.

Returned Value

Number from 0 through 1.

Parameters

None.

Get Dynamic HTML: The Definitive Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.