English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript Math.random() Method

 JavaScript Math Object

Math.random()The method returns a random number, ranging from 0 (including) to1(but not including).

Since random() is a static method of Math, you always use it asMath.random(), rather than as a method of the Math object created.

Syntax:

Math.random()
Math.random();
Test and see‹/›

Browser Compatibility

All browsers fully support the Math.random() method:

Method
Math.random()IsIsIsIsIs

Technical Details

Return value:Between 0 (including) and1Floating-point pseudo-random numbers between (excluding):
JavaScript version:ECMAScript 1

More examples

Return1to10Random number between:

Math.floor((Math.random() * 10) + 1);
Test and see‹/›

Return11to2Random number between 0:

Math.floor((Math.random() * 10) + 11);
Test and see‹/›

Return the random number of mouse movement:

Move the mouse pointer to the following DIV:

Hover the mouse over me!!!!

0.4194069268886713

 JavaScript Math Object