The 60-second answer
Characterize the source generator’s outcome probabilities before transforming it; do not assume modulo arithmetic preserves uniformity. Combine source draws to create equiprobable states, reject overflow states, and map the accepted range into the target outcomes.
Build the answer in this order
Characterize the source generator’s outcome probabilities before transforming it; do not assume modulo arithmetic preserves uniformity.
Combine source draws to create equiprobable states, reject overflow states, and map the accepted range into the target outcomes.
Prove unbiasedness by showing each target receives the same number/probability mass of accepted source states.
Quantify acceptance probability and expected number of source calls, then test empirical frequencies.
A useful interview mental model
This is the shape of a strong answer—not a script to memorize.
Senior-level signal
- Senior answers optimize the state-space size to minimize rejection while keeping the proof simple.
- Explain when exact unbiased sampling is worth extra calls versus an approximate method.
What the interviewer is really testing
Likely follow-up questions
Common weak-answer patterns
- Ignoring shape, dtype, device, masking, or broadcasting assumptions.
- Using a framework call without explaining the underlying operation.
- Skipping gradient, numerical-stability, and batching checks.