xxxxxxxxxx
function getRandomNumberBetween(min,max){
return Math.floor(Math.random()*(max-min+1)+min);
}
//usage example: getRandomNumberBetween(20,400);
xxxxxxxxxx
function randomRange(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
console.log(randomRange(1,9));
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 min = 1;
const max = 4;
const intNumber = Math.floor(Math.random() * (max - min)) + min;
console.log(intNumber); //> 1, 2, 3
xxxxxxxxxx
function randomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min)
}
console.log(randomInt(1, 6)) // random integer between 1 and 6
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;
}