javascript get random number in range
snippet in javascript

javascript get random number in range

user7835

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

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

Math.random javascript double

user804

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

javascript random number between 0 and 10

user8885

Math.floor(Math.random() * 10);

javascript random number in range

user1342

function getRandomIntInclusive(min, max) {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.floor(Math.random() * (max - min + 1)) + min; //The maximum is inclusive and the minimum is inclusive 
}

get random numbers javascript

user8430

//Write the following code to get a random number between 0 and n
Math.floor(Math.random() * n);

javascript random number in range

user2014

function getRandomInt(min, max) {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.floor(Math.random() * (max - min)) + min; //The maximum is exclusive and the minimum is inclusive
}