javascript get random number in range code example

Example 1: javascript get random number in range

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

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

Example 2: random in a range js

const rnd = (min,max) => { return Math.floor(Math.random() * (max - min + 1) + min) };

Example 3: javascript get random integer in given range

const randomInteger = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;

Example 4: Math.random javascript double

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

Example 5: javascript random number in range

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 
}

Example 6: javascript generate a random integer number in a range of numbers

const min = 1;
const max = 4;
const intNumber = Math.floor(Math.random() * (max - min)) + min;
console.log(intNumber); //> 1, 2, 3