Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

How to generate random number in JavaScript

//To genereate a number between 0-1 - > this will give you float 0.1569491123 - 0.98799941612
Math.random();
// Generated number can be rounded with -> Math.floor
Math.floor(Math.random())
/*To generate a number that is a whole number rounded down between
1 and 10 */
Math.floor(Math.random() * 10) + 1 //the + 1 makes it so its not 0.
Source by www.codegrepper.com #
 
PREVIOUS NEXT
Tagged: #How #generate #random #number #JavaScript
ADD COMMENT
Topic
Name
3+2 =