Montoya
asked on
math.random question
I have a fairly simple question:
Please explain the following based on this:
Math.floor(Math.random()*5 +1); -- I understand this gives me a random number from 0 up to and including 5.
why is math.floor needed?
why is 5+1 needed instead of just 6?
Please explain the following based on this:
Math.floor(Math.random()*5
why is math.floor needed?
why is 5+1 needed instead of just 6?
ASKER
why is 5+1 needed instead of just 6?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
.floor rounds down to the nearest whole number
.ceil rounds up to the nearest whole number