AP® Computer Science Principles

Free Version

Upgrade subject to access all content

Moderate

Random Numbers

APCSP-1XMEGH

Assume that the variable x is assigned the following value:

x ← RANDOM(0,10)

Recall that RANDOM(1, 10) will produce a random integer from 1 to 10, including 1 and 10. Which of the following code segments would ensure that x is a random number between 2 and 32?

A

x ← x * 2

B

x ← (x + 2) * 30

C

x ← (x * 30) + 2

D

None of these would work.