English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.
Math.random()
Math.random();Test and see‹/›
All browsers fully support the Math.random() method:
Method | |||||
Math.random() | Is | Is | Is | Is | Is |
Return value: | Between 0 (including) and1Floating-point pseudo-random numbers between (excluding): |
---|---|
JavaScript version: | ECMAScript 1 |
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:
0.4194069268886713