I'm looking to create a random number between two ranges that is a multiple of 10.
For example, if I fed the function the parameters 0, 100
it would return one of these numbers:
0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
but nothing like 63
or 55
.
And yes I'm aware this defeats the point of true "randomness", but I just need a quick easy way to get a number that's a multiple of 10 between two ranges.
Thanks. :)
I guess it can help:
var randomnumber=Math.floor(Math.random()*11)*10
it's just one line:
function rand_10(min, max){
return Math.round((Math.random()*(max-min)+min)/10)*10;
}
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