random()

The random() method is used to generate a random number between zero and 1. The value will obviously not be an integer. As with all mathematical methods, it is used with the Math object.

syntax:

Math.random(number)

EXAMPLE

document.write("The following is a randomly generated number : " + Math.random() );

The example shows a document.write statement that writes some applicable text to the screen, with a randomly generated number following it. One output is shown below.



The following is a randomly generated number : 0.9640102843992275