HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

JavaScript random() Method

Math Object Reference JavaScript Math Object

Example

Return a random number between 0 (inclusive) and 1 (exclusive):

Math.random();

The result could be:


Try it yourself »

Definition and Usage

The random() method returns a random number from 0 (inclusive) up to but not including 1 (exclusive).


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The random() method is supported in all major browsers.


Syntax

Math.random()

Return Value

Type Description
Number A Number from 0 up to but not including 1

Technical Details

JavaScript Version: 1.0


More Examples

Example

Return a random number between 1 and 10:

Math.floor((Math.random()*10)+1);

The result could be:


Try it yourself »

Example

Return a random number between 1 and 100:

Math.floor((Math.random()*100)+1);

The result could be:


Try it yourself »


Math Object Reference JavaScript Math Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE