21. Bias from random byte % 100
Code makes a 0–99 lucky draw number with `randomByte % 100`, where randomByte is uniform from 0 to 255. What is wrong?
- A.Nothing, because % keeps the spread uniform
- B.Only the value 0 is more likely than the rest
- C.Values 56–99 are more likely than 0–55
- D.Values 0–55 are 1.5 times as likely as 56–99
Show answer
Answer: D. Values 0–55 are 1.5 times as likely as 56–99
256 values do not split evenly into 100 buckets. 0–55 are hit by three bytes each (for example 5, 105, 205) and 56–99 by only two, so low numbers are 1.5 times as likely. Fix it with rejection sampling, for example drop bytes of 200 or more and try again, or use crypto.randomInt.
22. Weighted random server choice
Servers have weights [1, 3, 6], so prefix sums are [1, 4, 10]. A random r in [0, 10) is 4.5. Using 'first index whose prefix sum is greater than r', which server is picked?
- A.Index 2, with weight 6
- B.Index 1, with weight 3
- C.Index 0, with weight 1
- D.No server, because 4.5 is not a prefix sum
Show answer
Answer: A. Index 2, with weight 6
The prefix sums split [0, 10) into [0, 1), [1, 4) and [4, 10), whose widths match the weights. 4.5 falls in [4, 10), so index 2 is picked, and it will be picked 60% of the time. With many items, find the index by binary search in O(log n).
23. Making a Monte Carlo result 10× more precise
A Monte Carlo risk estimate uses 10,000 random samples. To cut its typical error by a factor of 10, about how many samples do you need?
- A.100,000
- B.20,000
- C.10,000,000,000
- D.1,000,000
Show answer
Answer: D. 1,000,000
The standard error of a Monte Carlo average falls like 1/√n. To divide the error by 10, √n must grow 10 times, so n must grow 100 times, from 10,000 to 1,000,000. This slow rate is why variance reduction tricks matter.
24. Why least squares is maximum likelihood
Under which assumption about the noise does minimising mean squared error give the maximum likelihood estimate of linear regression weights?
- A.Independent Laplace noise, constant scale
- B.Uniform noise on a fixed interval
- C.Independent Gaussian noise, constant variance
- D.Noise that grows in proportion to the target
Show answer
Answer: C. Independent Gaussian noise, constant variance
With independent Gaussian noise of fixed variance, the log-likelihood is a constant minus the sum of squared residuals divided by 2σ². Maximising it is the same as minimising squared error. Laplace noise would instead lead to minimising absolute error.
25. Spam probability from one word
40% of emails are spam. The word "lottery" appears in 50% of spam emails and 10% of normal emails. An email contains "lottery". Using Bayes rule, what is the probability it is spam (to two decimals)?
- A.0.77
- B.0.50
- C.0.83
- D.0.20
Show answer
Answer: A. 0.77
P(spam and word) = 0.4 × 0.5 = 0.20. P(normal and word) = 0.6 × 0.1 = 0.06. So P(spam | word) = 0.20 / (0.20 + 0.06) = 0.769, about 0.77. The 0.20 option forgets to divide by the total probability of seeing the word.
26. Precision when prevalence drops
At a fixed threshold a model has 80% recall and 95% specificity. Where 10% of cases are positive, its precision is 64%. You deploy it in a market where only 1% of cases are positive. What precision should you expect?
- A.About 64%
- B.About 14%
- C.About 80%
- D.About 95%
Show answer
Answer: B. About 14%
Per 1,000 cases at 1% prevalence: 10 positives give 8 true positives, and 990 negatives give 49.5 false positives. Precision is 8 / 57.5, about 14%. Recall and specificity do not depend on prevalence, but precision does, so the same model can look much worse in a new population.
27. Which plant made the faulty part
Plant A makes 60% of parts with a 2% defect rate. Plant B makes 40% with a 5% defect rate. A part is defective. What is the probability it came from plant A?
- A.0.375
- B.0.60
- C.0.40
- D.0.012
Show answer
Answer: A. 0.375
P(defect and A) = 0.6 × 0.02 = 0.012, and P(defect and B) = 0.4 × 0.05 = 0.020. So P(A | defect) = 0.012 / 0.032 = 0.375. Even though A makes more parts, B's higher defect rate makes it the more likely source.
28. A density value of 4
A probability density function for a measurement equals 4 at x = 0.1. Is that an error?
- A.Yes, densities must be at most 1
- B.Yes, it means the probability at x = 0.1 is 4
- C.Only if the variable is discrete
- D.No; densities can exceed 1 if the total area is 1
Show answer
Answer: D. No; densities can exceed 1 if the total area is 1
For a continuous variable, probabilities are areas under the density, not its height. A uniform distribution on [0, 0.25] has density 4 everywhere and total area 4 × 0.25 = 1. The probability of any exact value is zero.
29. Reading a Bayesian credible interval
A Bayesian analysis gives a 95% credible interval of 1.2% to 3.4% for a conversion lift. What can you say that a frequentist confidence interval does not literally allow?
- A.The lift is exactly 2.3%
- B.A 95% probability the lift is in the range
- C.95% of users had a lift inside this range
- D.The p-value is 0.05
Show answer
Answer: B. A 95% probability the lift is in the range
A credible interval is a probability statement about the parameter, given the prior and the data. A frequentist 95% interval is about the method: 95% of such intervals would contain the true value. Results depend on the prior, which should be stated.
30. Maximum likelihood for a click rate
An email is sent to 10 people and 7 click. Under a binomial model, what is the maximum likelihood estimate of the click probability?
- A.0.5
- B.0.07
- C.0.7
- D.1.0
Show answer
Answer: C. 0.7
The likelihood p^7 (1 − p)^3 is highest at p = 7/10 = 0.7, the sample proportion. MLE picks the parameter that makes the observed data most likely. With only 10 people, the uncertainty is large, which a confidence interval would show.