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
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)
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.