The random() method returns a random number from 0 (inclusive) up to but not including 1 (exclusive).
The random() method returns a random number from 0 (inclusive) up to but not including 1 (exclusive).
Math.random()
None
A Number, representing a number from 0 up to but not including 1
Return a random number between 1 and 10:
//display a random number between 1 and 10. var x = Math.floor((Math.random() * 10) + 1); console.log(x);/* w w w. j a v a2s . co m*/ //Return a random number between 0 (inclusive) and 1 (exclusive): console.log(Math.random()); //Return a random number between 1 and 100: console.log( Math.floor((Math.random() * 100) + 1));