Random Values MCQ Practice

Question 1 of 10

How many distinct integers can RANDOM(2, 2) produce?

  1. A. 3
  2. B. 0
  3. C. 1
  4. D. 2

Question 2 of 10

Which value can RANDOM(10, 12) produce?

  1. A. 13
  2. B. 0
  3. C. 9
  4. D. 11

Question 3 of 10

Code rolls two dice:

d1 ← RANDOM(1, 6)
d2 ← RANDOM(1, 6)
total ← d1 + d2

Which total is impossible?

  1. A. 1
  2. B. 2
  3. C. 7
  4. D. 12

Question 4 of 10

A weather simulation uses rainChance ← RANDOM(1, 100). Why is it incorrect to assume every run prints 50?

  1. A. Because simulations may not call RANDOM
  2. B. Because RANDOM(1, 100) has 100 equally possible integers, not a fixed 50
  3. C. Because RANDOM can only return 1
  4. D. Because RANDOM cannot return integers

Question 5 of 10

How many distinct integers can RANDOM(8, 12) produce?

  1. A. 12
  2. B. 4
  3. C. 5
  4. D. 8

Question 6 of 10

The table shows inclusive RANDOM ranges.

Call Possible values
RANDOM(1, 2) 1, 2
RANDOM(3, 5) 3, 4, 5
RANDOM(0, 1) ?

What replaces the question mark?

  1. A. 0, 1, 2
  2. B. 0 only
  3. C. 1 only
  4. D. 0, 1

Question 7 of 10

Expression: RANDOM(5, 1). On the AP CSP exam reference, a and b should satisfy a ≤ b for the usual inclusive range. Separately, assume a working interpreter requires a ≤ b. Which claim is safest for this course?

  1. A. Always write RANDOM with the smaller bound first, as in RANDOM(1, 5)
  2. B. RANDOM(5, 1) is required to return 100
  3. C. RANDOM never needs two arguments
  4. D. RANDOM(5, 1) must return only 5

Question 8 of 10

A game sets damage ← RANDOM(3, 5) + RANDOM(3, 5). Which damage value is impossible?

  1. A. 10
  2. B. 11
  3. C. 6
  4. D. 8

Question 9 of 10

Which statement correctly describes RANDOM(1, 3)?

  1. A. It returns only the average value 2
  2. B. It returns real numbers strictly between 1 and 3 exclusive
  3. C. It returns one of 1, 2, or 3, and repeated program runs may differ
  4. D. It returns 1, then 2, then 3 in a fixed cycle every call

Question 10 of 10

How many distinct integers can RANDOM(0, 0) produce?

  1. A. 2
  2. B. 10
  3. C. 0
  4. D. 1