xxxxxxxxxx
function randomRange(myMin, myMax) {
let result = Math.floor(Math.random() * (myMax - myMin + 1)) + myMin;
return result;
}
xxxxxxxxxx
function randomRange(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
console.log(randomRange(1,9));
xxxxxxxxxx
function getRandomNumberBetween(min,max){
return Math.floor(Math.random()*(max-min+1)+min);
}
//usage example: getRandomNumberBetween(20,400);
xxxxxxxxxx
function randomInRange(min, max) {
return Math.floor(Math.random() * (max - min) + min);
}
xxxxxxxxxx
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
xxxxxxxxxx
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
}
xxxxxxxxxx
const randomInteger = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
xxxxxxxxxx
const rnd = (min,max) => { return Math.floor(Math.random() * (max - min + 1) + min) };
Get a random number between range excluding terminals
xxxxxxxxxx
function randomWithoutMinMax(min, max) {
return Math.ceil(Math.random() * (max - min - 1)) + min;
}
Get a random number in range including terminals
xxxxxxxxxx
function randomWithMinMax(min, max) {
return Math.round(Math.random() * (max - min)) + min;
}
Get a random number in-between range excluding max
xxxxxxxxxx
function randomWithoutMax(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
Get a random number in-between range excluding min
xxxxxxxxxx
function randomWithoutMin(min, max) {
return Math.ceil(Math.random() * (max - min)) + min;
}
xxxxxxxxxx
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
}
xxxxxxxxxx
function randomNumberGeneratorInRange(rangeStart, rangeEnd) {
return Math.floor(Math.random() * (rangeStart - rangeEnd + 1) + rangeEnd);
}
console.log(`My random number: ${randomNumberGeneratorInRange(10, 50)}`);