AP CSP Topic 3.15: Random Values | Big Idea 3 | APCSExamPrep.com

AP CSP Course Big Idea 3 Topic 3.15: Random Values
🎓54.5% score 5s vs 9.6% nationally
5.0 Wyzant — 451+ reviews
📍Blue Valley North, Overland Park KS
3.15
AP CSP — Big Idea 3: Algorithms & Programming
CED Aligned • Exam Ready

Topic 3.15: Random Values

🎓 High School AP
💻 Python + AP Pseudocode
🎯 30-35% Exam Weight
📚 Interactive Lesson

🎯 Learning Objectives

  • Use RANDOM(a,b) to generate integers in a given range
  • Explain why programs use random values in simulations
  • Predict the range of possible outputs from a RANDOM expression
  • Identify independence between multiple RANDOM calls
📈
Exam Impact: Random values appear in AP CSP MCQ simulation questions and in Create Task programs that model real-world systems.
💡 Why This Matters

A coin flip simulation doesn't flip a physical coin -- it generates a random 0 or 1 and maps it to heads/tails. Random values let programs model unpredictable events at any scale.

RANDOM() in AP Pseudocode

The AP CSP reference sheet provides RANDOM(a, b) which returns a random integer between a and b, inclusive. Both endpoints are possible.

import random

flip = random.randint(0, 1)  # 0=heads 1=tails
roll = random.randint(1, 6)  # die roll
idx  = random.randint(0, 3)  # list index
flip <- RANDOM(0, 1)
roll <- RANDOM(1, 6)
idx  <- RANDOM(1, 4)

Range of RANDOM Expressions

For RANDOM(1,6) + RANDOM(1,6): min = 1+1=2, max = 6+6=12. Each call is independent -- getting 1 on the first doesn't change probabilities on the second.

Practice Problems

🔎 Practice MCQ
What is the range of values returned by RANDOM(3,8) * 2?
⚠️ Predict your answer BEFORE clicking.
🔎 Practice MCQ
A programmer writes x <- RANDOM(1,4) + RANDOM(1,4). Which value of x is NOT possible?
⚠️ Predict your answer BEFORE clicking.
🔎 Practice MCQ
A simulation needs to model an event happening ~30% of the time. Which correctly implements this with RANDOM(1,10)?
⚠️ Predict your answer BEFORE clicking.
🎮 Game
Random Range Calculator
Predict the minimum and maximum of random expressions. 8 questions.
0
Correct
1/8
Question
0
Streak 🔥
🤔 Evaluate:
0/8
correct
💻 Python Code Editor
Practice Problems
Write Python and check your answer. Paste into Replit for complex programs.
Problem 1 of 3
Simulate a die roll. Print a random integer 1-6. (Any 1-6 value accepted.)
Hint: print(random.randint(1, 6))
Problem 2 of 3
Print 'heads' or 'tails' by generating random 0 or 1.
Hint: if flip == 0: print('heads') else: print('tails')
Problem 3 of 3
Spot the bug: should randomly return 1-10 but always returns 10.
x = random.randint(10, 10)
Hint: randint(10,10) always returns 10. Fix: randint(1, 10)

Frequently Asked Questions

No. Computers use pseudorandom generators that appear random but are deterministic given a seed. For AP CSP purposes, treat RANDOM as truly random.
Use RANDOM(1,2) and check if result=1. Or RANDOM(0,1). Either gives 50/50.
Yes. Each call is independent. Getting 3 on the first call doesn't change the probability on the second.
📦
AP CSP Teacher SuperpackSlides, lesson plans, unit tests for all 5 Big Ideas — $249
Get the Superpack →

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]