Randomization

On this page 7

Randomization is the process of assigning experimental units to treatment and control groups by chance rather than by choice, rule or self-selection. In experimentation, it is the mechanism that makes groups comparable on average in every characteristic, measured or not, so that a difference in outcomes can be attributed to the treatment instead of to pre-existing differences.

Randomization is what separates a controlled experiment, such as an A/B test, from an observational comparison. It does not guarantee that two groups are identical in a single experiment, but it ensures that any imbalance is due to chance and therefore quantifiable. That property is the foundation for p-values, confidence intervals and the causal interpretation of experimental results.

Why randomization enables causal conclusions

Without randomization, the groups being compared usually differ in ways that also affect the outcome. Users who opt into a new feature are typically more engaged to begin with, so comparing them with non-users overstates the feature’s effect. This distortion is called selection bias or confounding.

Random assignment breaks the link between who receives the treatment and who they are. Engagement, device, location, age and every unmeasured trait are distributed across groups by the same chance process. With enough units, the groups become statistically equivalent before the treatment starts, and the remaining differences follow known probability distributions that statistical tests account for.

Randomization also protects against the experimenter’s own preferences. When people pick which customers, stores or patients receive a treatment, they tend to choose promising candidates, often without noticing. A random procedure removes that discretion.

Randomization designs

Several randomization designs exist, and the right one depends on sample size, known sources of variation and practical constraints. The table compares the most common ones.

DesignHow units are assignedMain advantageTypical use
Simple randomizationEach unit independently by a random drawEasy, no prior information neededLarge online experiments
Block randomizationRandom within small blocks of fixed sizeKeeps group sizes balanced over timeClinical trials with sequential enrollment
Stratified randomizationRandom within strata such as country or planBalances key variables, reduces varianceSmaller samples with strong predictors
Cluster randomizationWhole groups such as stores or schoolsAvoids contamination between unitsInterventions that act on groups
Switchback randomizationTime periods alternate between conditionsHandles shared resources and network effectsMarketplaces, pricing, logistics
Common randomization designs

Cluster designs need special care. Because units within a cluster resemble one another, the effective sample size is much smaller than the number of individuals, and analysis must account for the intra-cluster correlation. Ignoring it produces confidence intervals that are far too narrow.

Implementing randomization in online experiments

In digital products, randomization is usually implemented as deterministic hashing. The system combines a stable unit identifier with an experiment-specific salt, hashes the result and maps it to a bucket, for example one of 1,000. Buckets 0 to 499 receive control and 500 to 999 receive treatment.

ParameterTypical choiceWhy it matters
Randomization unitUser, account, device, session or requestMust match the level where the effect occurs
Hash function and saltStable hash with a unique salt per experimentPrevents correlated assignment across experiments
Traffic allocationOften 50/50 between two groupsEqual splits maximize statistical power
Assignment loggingRecord unit, group and exposure timeNeeded to detect errors and analyze correctly
Implementation parameters and their effects

Choosing the randomization unit is a design decision with consequences. Randomizing by session lets one person see both versions, which contaminates results for features with memory, such as pricing or onboarding. Randomizing by user avoids that, but logged-out visitors on several devices may still appear as different users.

Checking that randomization worked

Randomization can fail in practice even when the design is correct. Bugs in assignment, redirects, caching or data logging can make groups systematically different. Mature experimentation programs therefore run automatic validity checks before reading any result.

CheckWhat it detectsTypical action
Sample ratio mismatch testObserved group sizes differ from the planned splitStop interpretation and investigate assignment or logging
Covariate balance checkPre-experiment metrics differ between groupsInvestigate bugs; adjust analysis if chance imbalance
A/A testFalse positives in the whole systemRun two identical groups and confirm no difference
Exposure checkUnits assigned but never exposedAnalyze on assignment, investigate gaps
Validity checks for randomized experiments

A sample ratio mismatch is a strong warning sign. If an experiment planned as 50/50 shows 50.8% versus 49.2% across a million users, the chance explanation is extremely unlikely, and the results should not be trusted until the cause is found.

Pitfalls and limits of randomization

Randomization solves selection bias, but it does not solve every problem in experimentation. Several threats remain even with perfect random assignment.

  • Small samples can produce meaningful imbalance by chance; stratification or covariate adjustment reduces the risk.
  • Interference between units, such as shared inventory or social sharing, violates the assumption that one unit’s treatment does not affect another.
  • Post-assignment filtering, such as analyzing only users who completed a step that the treatment influenced, reintroduces selection bias.
  • Pseudo-random shortcuts, such as assigning by even or odd identifiers or by day of week, can correlate with real differences.
  • Novelty effects and short test durations limit how well results generalize.

The safest analysis follows the intention-to-treat principle: compare units by the group they were assigned to, not by what they actually experienced. This preserves the protection that randomization provides, at the cost of diluting the measured effect when some units never see the treatment.

A plain-language summary

Randomization means letting chance decide who gets what in a test. Think of flipping a coin for each customer. Heads sees the new website and tails sees the old one.

Because a coin has no preferences, both groups end up with a similar mix of people. There are similar numbers of loyal and new customers, of phone and computer users. If the groups then behave differently, the change is the most likely reason. Without the coin, people tend to pick groups that differ from the start.

An example from practice

A subscription news site wants to know whether a shorter signup form increases paid conversions. Earlier, the team had launched new designs for everyone and compared before and after, but holidays and news events made those comparisons unreliable.

This time, each visitor’s identifier is hashed with an experiment salt and assigned to the old or new form in a 50/50 split by user. On the third day, the automated check flags a sample ratio mismatch: the treatment group is about two percent smaller than expected. Engineers find that a caching rule served the old form to some treatment users. They fix it and restart the experiment.

After four weeks with balanced groups, the shorter form shows a clear increase in conversion with a confidence interval that excludes zero. Because assignment was random and verified, the team ships the change with confidence that the form, not the news cycle, caused the improvement.