Answers for "randomnumbergenerator range in js"

66

javascript get random number in range

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

//usage example: getRandomNumberBetween(20,400);
Posted by: Guest on July-23-2019
1

randomNumberGeneratorInRange in js

function randomNumberGeneratorInRange(rangeStart, rangeEnd) {
	return Math.floor(Math.random()*(rangeEnd-rangeStart +1)) +rangeStart
  // Or 
  //return Math.floor(Math.random()*(rangeEnd - rangeStart))+rangeStart
}

console.log(`My random number: ${randomNumberGeneratorInRange(5, 100)}`)
Posted by: Guest on March-21-2022
1

javascript random number in range

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
}
Posted by: Guest on January-27-2020
1

random number in range js

var min = 10, max = 25;
//inclusive random (can output 25)
var random = Math.round(Math.random() * (max - min) + min);
//exclusive random (max number that can be output is 24, in this case)
var random = Math.floor(Math.random() * (max - min) + min);
//floor takes the number beneath the generated random and round takes
//which ever is the closest to the decimal
Posted by: Guest on May-16-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language