Q:

javascript math.random between two numbers

// Between any two numbers
Math.floor(Math.random() * (max - min + 1)) + min;

// Between 0 and max
Math.floor(Math.random() * (max + 1));

// Between 1 and max
Math.floor(Math.random() * max) + 1;
12
//To genereate a number between 0-1
Math.random();
//To generate a number that is a whole number rounded down
Math.floor(Math.random())
/*To generate a number that is a whole number rounded down between
1 and 10 */
Math.floor(Math.random() * 10) + 1 //the + 1 makes it so its not 0.
25
Math.floor(Math.random() * 6) + 1  
14
Math.floor(Math.random() * (max - min + 1)) + min;

// Between 0 and max
Math.floor(Math.random() * (max + 1));

// Between 1 and max
Math.floor(Math.random() * max) + 1;
0
function getRandomNumberBetween(min,max){
    return Math.floor(Math.random()*(max-min+1)+min);
}
4
// Between 6 and 1
var randomNumber1 = Math.floor(Math.random() * (7 - 1)) + 1;
var randomNumber1 = Math.floor(Math.random() * ((max + 1) - (min))) + (min);
0

New to Communities?

Join the community