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 randomRange(min, max) {
2
3 return Math.floor(Math.random() * (max - min + 1)) + min;
4
5}
6
7console.log(randomRange(1,9));
1const rnd = (min,max) => { return Math.floor(Math.random() * (max - min + 1) + min) };
1var min = 10, max = 25;
2//inclusive random (can output 25)
3var random = Math.round(Math.random() * (max - min) + min);
4//exclusive random (max number that can be output is 24, in this case)
5var random = Math.floor(Math.random() * (max - min) + min);
6//floor takes the number beneath the generated random and round takes
7//which ever is the closest to the decimal