AP CSP 3.15 Exercise 2: Random Values Applied Challenge

Big Idea 3: Algorithms and Programming · Topic 3.15 · Exercise 2

Random Values: Applied Challenge

Six questions about the range RANDOM actually produces, and what randomness does and does not guarantee.

How this one is different

The range is inclusive on both ends. Half of the exam questions on this topic are decided by that one fact.

Applied Practice

6 questions · scenario driven · every answer is recorded for your teacher

Question 1 of 6Apply
What values can RANDOM(1, 6) produce?
Correct. The AP pseudocode RANDOM procedure is inclusive at both ends, so all six values are possible.
Incorrect. Excluding both endpoints is not how the procedure is defined.
Incorrect. Excluding the upper bound is the common wrong assumption, borrowed from other languages.
Incorrect. RANDOM produces any value in the range, not only the two endpoints.
Question 2 of 6Trace
How many distinct values can RANDOM(0, 9) return?
Incorrect. 8 excludes both endpoints.
Incorrect. 11 counts one value too many.
Incorrect. 9 forgets that 0 is included.
Correct. The values 0 through 9 inclusive are ten distinct values.
Question 3 of 6Transfer
Which expression produces a random even number from 2 through 10 inclusive?
Incorrect. This produces only 0 or 1.
Incorrect. This produces odd values as well as even ones.
Correct. The five values 1 through 5 map onto 2, 4, 6, 8, and 10 when doubled, which is exactly the required set.
Incorrect. Doubling a value already up to 10 reaches 20.
Question 4 of 6Analyze
A student runs a program using RANDOM twenty times and gets the value 3 only once out of a 1 through 5 range.
What is the correct conclusion?
Incorrect. An uneven small sample is the expected behavior of randomness, not evidence of a defect.
Correct. Each value is equally likely on each draw, but equal likelihood only shows up as even counts over many trials.
Incorrect. The observed values fall within the range, so nothing indicates a range error.
Incorrect. Nothing in the description points to a defect in the program logic.
Question 5 of 6Evaluate
A program that uses randomness must be tested.
What makes testing it harder, and what is a standard response?
Correct. The response is to test properties that must hold on every run, such as the range, and to use repetition rather than a single expected value.
Incorrect. Randomness does not meaningfully slow execution.
Incorrect. Fixing the randomness is a useful testing technique, but permanently removing it changes the program.
Incorrect. Randomized programs are tested routinely. Skipping is not an option.
Question 6 of 6Apply
A simulation should produce heads about half the time.
Which condition models a fair coin?
Incorrect. Three values with one selected is a one in three chance.
Incorrect. No value in the range exceeds 2, so this is never true.
Incorrect. This range has a single value and is always true.
Correct. Two equally likely values with one selected gives a one in two chance, which is a fair coin.

Where to go next

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]