Page 1257 - AP Computer Science A, 7th edition
P. 1257
34. (C) Suppose you want random integers from 2 to 8, that is, low = 2 and high = 8. This is 7 possible integers, so you need
(int) (Math.random() ∗ 7)
which produces 0, 1, 2, ..., or 6. Therefore the quantity
(int) (Math.random() ∗ 7) + 2
produces 2, 3, 4, ..., or 8. The only expression that yields the
right answer with these values is
(int) (Math.random() ∗ (high – low + 1)) + low;