Link to home
Start Free TrialLog in
Avatar of Montoya
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?
Avatar of Gary
Gary
Flag of Ireland image

To make sure its a whole number and not something like 2.56584
.floor rounds down to the nearest whole number
.ceil rounds up to the nearest whole number
Avatar of Montoya
Montoya

ASKER

why is 5+1 needed instead of just 6?
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial