1// Between any two numbers
2Math.floor(Math.random() * (max - min + 1)) + min;
3
4// Between 0 and max
5Math.floor(Math.random() * (max + 1));
6
7// Between 1 and max
8Math.floor(Math.random() * max) + 1;
1function getRandomNumberBetween(min,max){
2 return Math.floor(Math.random()*(max-min+1)+min);
3}
4
5//usage example: getRandomNumberBetween(20,400);
6
1function randomInRange(min, max) {
2 return Math.floor(Math.random() * (max - min) + min);
3}
1const randomInteger = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
1const min = 1;
2const max = 4;
3const intNumber = Math.floor(Math.random() * (max - min)) + min;
4console.log(intNumber); //> 1, 2, 3
1function getRandomInt(min, max) {
2 min = Math.ceil(min);
3 max = Math.floor(max);
4 return Math.floor(Math.random() * (max - min)) + min; //The maximum is exclusive and the minimum is inclusive
5}
6