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?
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);
jsFiddle DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With