random number javascript
snippet in javascript

how to generate a random number in javascript

user580

//To genereate a number between 0-1
Math.random();
//To generate a number that is a whole number rounded down
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.

random number javascript

user6377


Math.floor(Math.random() * 100);     // returns a 
  random integer from 0 to 99
 

js random number

user7482

var random;
var max = 8
function findRandom() {
  random = Math.floor(Math.random() * max) //Finds number between 0 - max
  console.log(random)
}
findRandom()

javascript random number

user665

var RandomNumber = Math.ceil(Math.random() * 100);              
// Returns a random number between 1 and 100

random number javascript

user9639

function getRandomNumberBetween(min,max){
    return Math.floor(Math.random()*(max-min+1)+min);
}

//usage example: getRandomNumberBetween(20,400); 

random number javascript

user600

function getRandomNumberBetween(min,max){
    return Math.floor(Math.random()*(max-min+1)+min);
}
getRandomNumberBetween(50,80);