1//To genereate a number between 0-1
2Math.random();
3//To generate a number that is a whole number rounded down
4Math.floor(Math.random())
5/*To generate a number that is a whole number rounded down between
61 and 10 */
7Math.floor(Math.random() * 10) + 1 //the + 1 makes it so its not 0.
1function getRandomNumberBetween(min,max){
2 return Math.floor(Math.random()*(max-min+1)+min);
3}
4
5//usage example: getRandomNumberBetween(20,400);
6
1Math.floor((Math.random() * 100) + 1);
2//Generate random numbers between 1 and 100
3//Math.random generates [0,1)
1// min value of the random number
2var min = 5;
3
4// max value of the random number
5var max = 25;
6
7// generate the random number
8var rdm = (Math.random() * (max - min)) + min
9
10// generate the random number without "."
11var rdm = Math.round((Math.random() * (max - min)) + min)
1// Returns an integer between min and max (the maximum is exclusive and the minimum is inclusive)
2function getRandomInt(min, max) {
3 min = Math.ceil(min);
4 max = Math.floor(max);
5 return Math.floor(Math.random() * (max - min) + min);
6}
7
1var randomnumber = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
2