hisoka Posted March 2, 2016 Share Posted March 2, 2016 Generally why we use Math.floor together with Math.random ? for example like this : Math.floor(Math.random()*15)+1; or any other context Link to comment Share on other sites More sharing options...
dsonesuk Posted March 2, 2016 Share Posted March 2, 2016 it rounds a number down to nearest integer value, since random() produces a value between 0 and 1 NOT including 1, I might add. simple example highest random 0.99 0.99 * 15 = 14.85 using floor() = 14 14+1 = 15 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now