# Math.random()

Bill Boyle

Greenhorn

Posts: 12

posted 12 years ago

While taking a practice test I ran across this question:

What is the value of the following expression:

Math.round(Math.random() + 2.50001);

A. 2

B. 3

C. It is impossible to say

I thought the answer should be C, but the book said B. Most the time the result should be 3. But is it possible for random() to return .999999

It that case the value would be 4.

What is the value of the following expression:

Math.round(Math.random() + 2.50001);

A. 2

B. 3

C. It is impossible to say

I thought the answer should be C, but the book said B. Most the time the result should be 3. But is it possible for random() to return .999999

It that case the value would be 4.

Thank you,<br />Bill Boyle

Mani Ram

Ranch Hand

Posts: 1140