1function getRandomNumberBetween(min,max){
2 return Math.floor(Math.random()*(max-min+1)+min);
3}
4
5//usage example: getRandomNumberBetween(20,400);
6
1function randomNumber(min, max) {
2 return Math.random() * (max - min) + min;
3}
1//Returns random Int between 0 and 2 (included)
2Math.floor(Math.random()*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
1function getRandomInt(min, max) {
2 min = Math.ceil(min);
3 max = Math.floor(max);
4 return Math.floor(Math.random() * (max - min + 1)) + min;
5}
1/* If 1 argument is given, minimum will be set to 0 and maximum to this argument
2 * If 2 arguments were given, the fist would be the minimum and the second the maximum
3 * The function will return an integer in [min, max[
4 */
5const Math.randint = function (min,max) {
6 [min,max] = (max===undefined)?[0,min]:(min>max)[max,min]:[min,max];
7 return Math.floor(Math.random*(max-min)+min);
8}