JavaScript & jQuery Tutorials

JS Home Right Arrow JS Reference Right Arrow Math Right Arrow random()

random()  Math  class method

Description

Returns a floating point random number between 0 (inclusive) and 1 (exclusive).

  • Like all class methods random() should be used on the class rather than an instance of the class.

Syntax


Signature Description
Math.random()Returns a floating point random number between 0 (inclusive) and 1 (exclusive).

Parameters

None.

Examples

The code below displays random() usage.


// Store results in an array.
var randomValues = new Array(6);
randomValues[0] = Math.random();
randomValues[1] = Math.random();
randomValues[2] = Math.random();
randomValues[3] = Math.random();
randomValues[4] = Math.random();
randomValues[5] = Math.random();
alert(randomValues);  

Press the button below to action the above code:

Related Tutorials

JavaScript Advanced Tutorials - Lesson 4 - Math



  

go to home page Homepage go to top of page Top