Unit 1 Day 12: Math.random() Range Practice
Share
Unit 1, Section 1.12
Day 12 Practice • January 18, 2026
🎯 Focus: Math.random() Ranges
Practice Question
Which expression generates a random integer from 10 to 25, inclusive?
What This Tests: This question tests the formula for generating random integers in a specific range. This is one of the most commonly tested Math.random() concepts on the AP exam.
Key Concept: Random Integer Formula
// Formula for random int from min to max (inclusive):
(int)(Math.random() * (max - min + 1)) + min
// For 10 to 25:
// Range = 25 - 10 + 1 = 16 possible values
(int)(Math.random() * 16) + 10
Why It Works
| Step | Range |
|---|---|
| Math.random() | [0.0, 1.0) |
| Math.random() * 16 | [0.0, 16.0) |
| (int)(Math.random() * 16) | 0 to 15 |
| (int)(Math.random() * 16) + 10 | 10 to 25 |
Common Mistakes
Mistake: Answer C (using 15)
Using 15 instead of 16 gives range 10-24, missing 25. Remember: add 1 to include both endpoints!
Mistake: Answer A (using 25)
This gives range 10-34, way too large! The multiplier should be the count of possible values, not the max.
Quick Reference
💡 Memorize This Formula
Random int from min to max (inclusive):
(int)(Math.random() * (max - min + 1)) + min
Common examples:
• 1-6 (dice): (int)(Math.random() * 6) + 1
• 0-99: (int)(Math.random() * 100)
• 5-10: (int)(Math.random() * 6) + 5
Difficulty: Hard • Time: 2-3 minutes • AP Skill: 3.A - Write expressions
Want More Practice?
Master AP CSA with guided practice and expert help
Schedule 1-on-1 Tutoring Practice FRQs