Longest Run of Heads or Tails

Longest Run of Heads or Tails

Note: Please adjust width of browser if only one column is visible.


Change of specified run length will impact marked runs in current plot


Click Generate to re-randomize outcomes based on current number of trials


Shiny app by Jimmy Doi
Base R code by Jimmy Doi
Shiny source files: GitHub Gist
Cal Poly Statistics Dept Shiny Series

If a fair coin is flipped 100 times and a streak of 7 heads (or tails) in a row is observed, is that an unusual result? To answer this we can simulate tosses of a fair coin and keep track of runs of heads or tails.

This Shiny app allows you to simulate the outcomes of a coin flipped n times. You can specify the probability of heads (default is 50%). Any runs of at least the length you specify will be marked in color, and the length of the longest run will be given. You may also choose to display the predicted approximate length of the longest run and an approximate 95% prediction interval for the length of the longest run. Details on these two estimators can be found in the first reference below.

More information on the length of the longest run can be found in the following journal articles:

Schilling, M. 'The Longest Run of Heads' The College Mathematics Journal , 21(3), 196--207
Schilling, M. 'The Surprising Predictability of Long Runs' Mathematics Magazine , 85(2), 141--149