Practice Random Numbers in CS Thinking
Use these practice problems to test your method after reviewing the concept explanation and worked examples.
Quick Recap
Random numbers are values chosen without a predictable pattern, or in computing, values that imitate that behavior closely enough for practical use. Computers often generate pseudo-random numbers using algorithms that look random even though they are created deterministically.
The computer follows a rule, but the outputs are mixed enough to behave like random choices for many tasks.
Showing a random 20 of 50 problems.
Example 1
mediumEstimating by throwing random points in a unit square and counting those inside the quarter circle: if 785 of 1000 land inside, estimate .
Example 2
mediumA simulation runs 6000 fair die rolls. Roughly how many 3's should you expect, and will the count be exactly that?
Example 3
challengeA flawed PRNG only outputs even numbers from 0 to 9 (0,2,4,6,8). A student uses it to simulate a fair 10-sided die. List two distribution flaws this causes.
Example 4
mediumYou want a random integer from 5 to 15 using `randint`. What call should you use, and how many possible outputs are there?
Example 5
easyA fair 20-sided die is rolled. What is the probability of rolling a 13?
Example 6
hardA PRNG outputs values 0..9 but produces 0 twice as often as any other digit. Compute and .
Example 7
easyA fair coin is flipped 4 times. What is the probability of getting exactly 4 heads?
Example 8
challengeYou need an unbiased random bit but your coin is biased (P(heads)=, ). Describe von Neumann's trick to extract a fair bit.
Example 9
mediumA simulation expects a uniform distribution over 1-100 but the generated values cluster near 1-10. What likely went wrong, by the common mistake?
Example 10
hardRolling two dice repeatedly until the sum equals 7, what is the probability of getting it on the first try?
Example 11
easyYou roll a fair die. What is the probability of rolling a number greater than 4?
Example 12
mediumA test must be reproducible but uses random data. How do you get fresh-looking randomness yet identical runs each time?
Example 13
mediumRolling two fair dice and summing, what is the probability the sum is 7?
Example 14
easyTrue or false: a PRNG with a known seed produces predictable output to anyone with the algorithm.
Example 15
easyA pseudo-random generator is seeded with the same seed twice. How do the two output sequences compare?
Example 16
easyWhat is the input to a pseudo-random generator that determines its starting state?
Example 17
mediumTo simulate a 25% chance event using `random.random()` returning , what condition should you check?
Example 18
hardDrawing 2 cards from a 52-card deck without replacement, what is the probability both are hearts?
Example 19
mediumA fair 4-sided die outputs . What is the expected value of one roll?
Example 20
easyAre pseudo-random numbers truly unpredictable to someone who knows the algorithm and seed?