i need to generate a random number between -100 and a variable 'max_top' ( will always be a positive number, up to roughly 40). The number needs to be able to be a minus as well as positive.
how can i do this?
Answer
You dont need JQuery for this:
var minNumber = -100;
var maxNumber = 40
var randomNumber = randomNumberFromRange(minNumber, maxNumber);
function randomNumberFromRange(min,max)
{
return Math.floor(Math.random()*(max-min+1)+min);
}
console.log(randomNumber);
No comments:
Post a Comment