+ 1
random() range
How do I get a random number between a certain range in JavaScript? Say range 95 to 100 for example
2 Respostas
+ 14
you can use this
function randVal(min,max){
return Math.floor(Math.random()*(max-min+1)+min);
}
then just pass the min and max values
var x=randVal(95,100);
+ 4
Math.random() produces a random no. between 0 and 0.99....
So we can map it between the no.s we want by multiplying it with the max no. , remove the decimal , adding min as @Burey wrote , Try solving it on a paper with random no. between 0 and 1 then you will understand it better