This interview question evaluates statistical assumptions, formulas, estimation strategy, uncertainty, edge cases, and interpretation in a realistic interview setting. A strong answer for Design tests to verify shuffle randomness states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.
How would you test whether your array shuffling function is truly random? Outline an experiment: define null and alternative hypotheses, select statistical tests (e.g., chi-square goodness-of-fit on position frequencies and tests for pairwise independence), determine sample size and significance level, and describe how you'd detect bias or correlations. Explain how you would implement and automate these tests in JavaScript.
Quick Answer: This interview question evaluates statistical assumptions, formulas, estimation strategy, uncertainty, edge cases, and interpretation in a realistic interview setting. A strong answer for Design tests to verify shuffle randomness states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.
hardSoftware EngineerTechnical ScreenStatistics & Math
2
0
Design tests to verify shuffle randomness
Experiment Design: Is Your Array Shuffle Truly Random?
You're given a shuffle(arr) function that takes an array of n distinct items and returns a random permutation. Design a rigorous test plan to assess whether the shuffle is uniform and independent across runs.
Requirements:
State hypotheses
Null and alternative hypotheses for uniformity over permutations and independence across runs.
Specify tests
Position uniformity (e.g., chi-square goodness-of-fit/independence on item-by-position counts).
Pairwise order/adjacency tests to probe correlations between items.
Any additional tests to catch common implementation bugs.
Choose sample size and significance level
Derive or justify trial counts T, alpha, power, and multiple-testing correction.
Bias/correlation detection
How to localize and diagnose nonuniformity or dependence.
Implementation and automation in JavaScript
Outline data collection, statistics, p-values, pass/fail logic, and CI strategy.
Assume: We can call shuffle repeatedly as a black box. We can choose n (e.g., 10–52) and run T trials.
Constraints & Assumptions
Preserve the scope, facts, inputs, and requested outputs from the prompt above.
If the prompt leaves a detail unspecified, state a reasonable assumption before relying on it.
Keep the answer interview-ready: concise enough to present, but concrete enough to implement or evaluate.
Clarifying Questions to Ask Guidance
Clarify the random variables, distributional assumptions, independence assumptions, and desired output.
Show enough derivation for the interviewer to follow the reasoning.
Explain how you would validate the result with simulation or sensitivity checks.
What a Strong Answer Covers Guidance
A correct setup with definitions, formulas, and boundary conditions.
A step-by-step derivation or estimation plan.
Interpretation of the result, including uncertainty and practical limitations.
Checks for assumptions, edge cases, and numerical stability.
Follow-up Questions Guidance
How would the result change if the assumptions were relaxed?
Can you verify the answer with a simulation?
What is the most likely source of estimation error?