How to randomize

Steve Simon


This page is currently being updated from the earlier version of my website. Sorry that it is not yet fully available.

*Dear Professor Mean

Dear Baffled,

Here’s a lightbulb randomization joke: take to in How many a screw does statisticians it lightbulb?

There are also two quotes that are relevant here: “Random selection is too important to be left to chance” and “Random is not haphazard”. The latter quote can be found in Statistically Speaking. A Dictionary of Quotations by C.G. Gaither and A.E. Cavazos-Gaither.

Short answer

The simplest way to randomize is to

  1. list your treatments and controls in a systematic order,
  2. attach a random number to each row
  1. sort by the random number.

This works for simple randomization

Why randomization is important.

I’m glad that you are interested in randomization. Some people think it is fine just to alternate regularly between treatment and control. But there are two problems with this.


This same sort of large-small pattern can occur in medical situations. For example

A second problem with alternating is that many studies are blinded. An alternating schedule may make it easy for someone to guess what patients get what treatment


Let me show you this in Excel


Your random numbers will be different than these. Otherwise

To randomize


By the way

When I work out these examples

What is block randomization?

If there is the possibility that the experiment will not reach your target sample size

A solution to this problem is to divide your study up into blocks and then randomize within each block. If the study ends at a block boundary, then you are guaranteed to have perfect balance between treatments and controls. If a study ends in the middle of a block

In Excel


Now we sort the numbers


Notice that the first block has the order TCTC

How do I randomize in a matched pairs study?

You can randomize a matched pairs study the same way as with block randomization. In a matched study

The easy way to do this is to allocate two rows for each patient and label the rows T and C in a systematic order. Add random numbers and then sort within each patient.

Here’s an a example of how we would set up a matched pairs example for six patients.


Sort the data by patient and by random number within each patient.


Notice that patients 1,3

Assigning random id numbers for anonymization

Suppose you want to create an identification code that is effectively random. You want to avoid medical record numbers because they would compromise security. There are several approaches that work. A simple approach is to list the numbers 1001

Here’s the medical record number

Sort the last two columns only to get a shuffled list of IDs.

Keep this list in a secure location. Use only the ID column when sending your data out beyond the hospital. This approach protects the privacy of individual subjects.

Whenever you are concerned about privacy in a research study


In an August 10


Baffled Beth does not know how to properly randomize subjects for her research study. Professor Mean explains how randomization differs from allocating the treatment and control in an alternative fashion. He shows a simple approach for randomization

  1. arranging your treatments in a systematic order,
  2. attaching a column of random number to this list
  1. sorting by the random number column.

He then shows examples for s**imple randomization

Further Reading

There’s an interesting two page article in the British Medical Journal on randomisation (notice the alternate spelling. I feel so intellectual when I replace all my z’s with s’s.)

  1. **Altman DG

You can find an earlier version of this page on my original website.