0
Is there a best way to round a random number between 0-100?
Math.round(Math.random()*100)
4 Answers
+ 5
Math.random()*100 //possible highest output 99.99 after floor 99
Math.random()*4 //possible highest output 3.99 after floor 3
Math.random()*n produces highest number is (n-1).
So Math.random()*101 will output highest 100.999 after floor will be 100
+ 2
Math.floor(Math.random()*101)
0
Thanks Sayed. floor returns the largest integer less than or equal to a given number. I want to round it. I'm curious why do you use 101?
0
Great. Thanks