PLEASE HELP! Putting as many points here as I can

In the Guess My Number game, there is a lower limit and an upper limit for the range of possible numbers to guess. If the lower limit were inclusive and the upper limit exclusive, which expression would properly generate values for the secret number?

(int)(Math.random() * (upper − lower) ) + lower
(int)(Math.random() * (upper − lower + 1) ) + lower
(int)(Math.random() * (upper − lower) ) + lower + 1
(int)(Math.random() * (upper − 1 − lower) ) + lower + 1
(int)(Math.random() * (upper − lower + 1) ) + lower − 1

Respuesta :

Answer:

(int)(Math.random() * (upper − lower) ) + lower

Explanation:

Math.random gives us some random value. To get that value within bounds we multiply random value with the difference between upper and lower bound.

Now to make lower bound inclusive we add lower bound to result

Answer:

A is the correct answer. Pay close attention to what the question is asking, because there is more than one question that looks similar. If you got it wrong it is probably you didn't look at what the question is asking. But the actual answer is A.  I took the test and this was my question too.

ACCESS MORE