0
Q:

generate random number between two numbers javascript

// 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
var difference = function (a, b) { return Math.abs(a - b); }
2
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 randomInRange(min, max)
{
	return Math.floor(Math.random() * (max - min + 1) + min);
}
0
// 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