|<<
<<
>>
>>|
Speed Scale: %
Avg Speed: bits per second bps
flips.
#Flips: 0
#Flips: 
0
#Heads: 
0
 (
%)
#Tails: 
0
 (
%)
Avg FPS: 0

Current #heads streak: 0
Current #tails streak: 0

Longest #heads streak: 0
Longest #tails streak: 0

Expected Avg. Longest streak: 0

Coin Toss Streak Probability Calculator

To see at least heads in a row with a probability of 63.21%, it would require 1 coin flip(s).

If you flipped a coin every second, it would take 1 second to flip it that many times. Doing this would give you a 50% chance of seeing a streak of 1 or more heads in a row.


Expected Avg. Longest Streak Calculator

For coin flips, the expected average longest streak of heads is 0.5


artbylogic.com
X

Coin Toss

Version 1.0
Overview:
This application simulates tossing a fair coin and provides some statistics about the number of coin flips in a box below the flippable coin. These statistics include the number of heads and tails seen, the current and longest run of heads and tails, the expected average longest run of heads (or tails) expected, the number of flips and the automated average FPS (flips per second). It also allows one to automate the coin flipping (via a checkbox at the top) for faster results.

To flip a coin for the first time, just click on the "Flip!" button near the top of the page. For subsequent coin flips, simply click on the image of the coin (either heads or tails).

If you need to toss a coin and don't have a physical one handy, or maybe don't trust the tosser, look no further!

Below the Coin Flip Statistics Box, there are two calculators: a 'Coin Toss Streak Probability Calculator' and a 'Expected Avg. Longest Streak Calculator'.

Note that the coin flips are randomly generated using an approach used on our NDRNG page that uses a combination of an algorithm and entropy sources. Although it is not state secret encryption grade level randomness, it does provide a very good source of randomness that cannot practically be predicted and which has passed various tests of randomness to which it has been subjected.

Coin Toss Streak Probability Calculator
With this calculator, you can calculate the number of expected coin flips needed to see a specified minimum number of heads in a row for a specific probability percentage.

Expected Avg. Longest Streak Calculator
With this calculator, you can calculate the expected average longest streak (of heads or of tails) for the entered number of flips.

It might be useful to explain some of the concepts at play here with some examples:

1 Coin Flip:
Let's take the simplest example of 1 coin flip. You can either get a Heads (H) or a Tail (T) with 1 flip. The probability of getting at least 1 H in a row is 50%.

The average expected run length is the sum of the possible run lengths divided by the number of permutations. We have 0 heads in a row or 1 head in a row as the only possible options for 1 coin flip. In this case, we have (0 + 1)/2 = 0.5. If you flip the coin one time up above, you will see that the expected average displays as 0.5 in the Coin Flip Statistics box.

2 Coin Flips:
With 2 coin flips you will see one of the following sequences: HH, HT, TH, TT. Of these 4 equally likely (for a fair coin) outcomes, 3 of them have a run of at least 1 H. Thus, there is a 75% chance of seeing at least 1 H in a row after 2 coin flips. Note that there is only one outcome that has at least 2 H's in a row. Thus, there is a 25% chance of seeing at least 2 H's in a row after 2 coin flips.

Looking again at the possible outcomes of HH, HT, TH, and TT, the average expected run length for 2 coin flips = (2 + 1 + 1 + 0)/4 = 1. Here we count the run of heads in each of HH (2), HT (1), TH (1), and TT (0), and then divide by the number of possible permutations (i.e. 4).

3 Coin Flips:
With 3 coin flips you will see one of the following sequences: HHH, HHT, HTH, HTT, THH, THT, TTH, TTT. Of these 8 equally likely outcomes, 7 of them have a run of at least 1 H. Thus, there is a 87.5% (i.e. 7/8) chance of seeing at least 1 H in a row after 3 coin flips. Looking it over, you will see that 3 of these permutations have at least 2 H's in a row. That amounts to a 37.5% (i.e. 3/8) chance of seeing at least 2 H's in a row after 3 coin flips. Also note that there is only one outcome that has at least 3 H's in a row. Thus, there is a 12.5% (i.e. 1/8) chance of seeing at least 3 H's in a row after 3 coin flips.

The average expected run length for 3 coin flips = (3 + 2 + 1 + 1 + 2 + 1 + 1 + 0)/8 = 1.375. Here each number in the sum comes from the length of the longest string of H's in each of the outcomes respectively. This value of 1.375 matches what is shown next to "Expected Avg. Longest streak:" above for 3 coin flips.

Coin Toss Streak Probability Calculator and Discrete Probability Percentage Values

Note that for a given minimum number of heads in a row, there are discrete values for the probability percentages. This can be seen in the following chart for a minimum of 2 heads in a row:


Minimum #Heads in a Row: 2
#FlipsProbability of >= 2 consecutive H'sPermutations
10%H, T
225%HH, HT, TH, TT
337.5%HHH, HHT, HTH, HTT, THH, THT, TTH, TTT
450%HHHH, HHHT, ..., TTTT
.........

So what happens in the 'Coin Toss Streak Probability Calculator' if you enter a percentage that is not one of these discrete values? We basically use the next highest existing discrete value. The Probability field is updated to show the actual probability. So, for a minimum number of 2 heads in a row, if you enter a percentage in the range of 25.01% to 37.50% the returned number of flips will be the same as what is associated with a percentage of 37.5%.

As the minimum number of heads in a row increases, the max difference between successive discrete probability percentages decreases. In fact, by the time we get to 13 heads in a row, there are no longer any gaps in the percentages (to 2 decimal places).

Note that we allow setting the probability from 0 to 99.99 for up to 2 decimal places when the minimum number of heads in a row is less than or equal to 20. When the minimum number of heads in a row is greater than 20, we use a different approach that does not allow changing the probability. The probability for this approach is fixed at 63.21%. Why 63.21%? We will get to that shortly.

You can enter a value of 100 for the probability percentage, but this will always return an infinite number of flips needed since there is always a possible outcome (no matter how many flips taken) of all Tails (meaning no heads in a row). Such an outcome becomes more and more unlikely probability-wise as the number of coin flips increases, but it is a non-zero probability.


Digging Deeper... and 63.21%

For a minimum number of heads in a row less than or equal to 20, I calculated the exact number of flips needed for the probability percentage entered by using the Generalizations of Fibonacci numbers. This calculation finds the exact number of flips needed for a given probability and minimum number of heads in a row. This was verified as explained later on below. Here is a sequence (described below) used for at least 4 heads in a row that gives the number of permutations for 1 flip, 2 flips, 3 flips, ...

For a minimum of 21 heads in a row and greater, I use the formula F = 2^(N+1) - 2, where F = the number of flips, and N = the minimum number of heads in a row. This formula does not use the desired probability to determine the number of flips, so out of curiosity, I compared the results with the exact values I had determined for less than 21 heads in a row. I found that the probability used in the calculation approaches (1 - 1/e) as N increases, which is 63.21% (to 2 decimal places). Interestingly, this limit appears in a related probability problem.

Now is a good time to back up and go into more detail on how I calculated and verified my work. Initially, I calculated the probabilities associated with different number of heads in a row for various number of flips of a fair coin. Here it is for 4 flips. In the table below, each row represents a unique outcome from a series of 4 coin flips. For the 'Permutations' column, a "0" represents a Tails outcome and a "1" represents a Heads outcome.

Number of Coin Flips: 4
PermutationMax #Heads in a Row
00000
00011
00101
00112
01001
01011
01102
01113
10001
10011
10101
10112
11002
11012
11103
11114

There are 7 permutations with exactly 1 heads in a row, 5 with exactly 2 heads in a row, 2 with exactly 3 heads in a row, and 1 with exactly 4 heads in a row. These are the values added in the table below to determine the probabilities for minimum number of heads in a row.

From this, I calculated the probabilities for at least 1 heads in a row, at least 2 heads in a row, etc. Here, '1+' indicates at least 1 heads in a row. There are a total of 16 possible permutations with 4 coin flips (2^4 = 16).

Number of Coin Flips: 4
Minimum Heads In a RowProbability of seeing in 4 Coin Flips
1+7/16 + 5/16 + 2/16 + 1/16 = 15/16 = 93.75%
2+5/16 + 2/16 + 1/16 =
8/16 = 50.00%
3+2/16 + 1/16 =
3/16 = 18.75%
4+1/16 =
1/16 =
6.25%

You can verify these table values with Wolfram Alpha by clicking on the percent values in the second column of the table.

We can also calculate the average of the longest run from this data: Avg of Longest Run = (0 + 7*1 + 5*2 + 2*3 + 1*4)/16 = 27/16 = 1.6875

This data (and other flips data I calculated) was used to verify later work.


Next, for a given minimum number of heads, for each number of flips starting at 1 (up to the number of flips needed to get a probability of 99.99%), I calculated the probability (using a computer program I wrote). I did this for a minimum number of heads from 1 to 20. I stopped at 20 because the time to run the computer program started taking days to complete. I use the output of this program as a lookup table when the number of heads in a row is less than or equal to 20.

This program uses a generalization of the Fibonacci sequence. Following is an example of the calculations used for 4 flips:

For my program, I basically was interested in the following problem: Given, N = minimum number of heads in a row, and F = number of coin flips, find the probability of N+ heads in a row for F flips. Note that our notation uses parens instead of subscripts, so that a(F) corresponds to a with a subscript of F. Here is a link to a site that provides an alternate way to calculate the probability given N and F, but I found it to be slow as F increased.

For a given N, we will calculate a(F) which is the number of permutations with N+ heads in a row for F coin flips. The following examples use N=4.

a(F) = 2^F - b(F) where the series b(1), b(2), b(3), ... is the Tetranacci sequence that tells the number of ways of not getting N heads in a row. Starting with the initialization values 0, 0, 0, 1 we calculate b(0) as the next term in this sequence. Succeeding values, for a Tetranacci sequence, are the sum of the previous 4 (hence, tetra) values. Thus, b(0) = 1, b(1) = 2, b(2) = 4, b(3) = 8, b(4) = 15, b(5) = 29, b(6) = 56, ...

Note that the following formulas hold:
  • b(m) = 2^m for 1 <= m < N
  • b(N) = 2^N - 1
  • b(F) = b(F-1) + b(F-2) + ... + b(F-N) for F > N

To summarize, for N=4, b(F) starting at F=1:   2, 4, 8, 15, 29, 56, 108, 208, 401, ...

Last example: b(6) = b(5) + b(4) + b(3) + b(2)    stop at subscript 2. Just include N terms. (56 = 29 + 15 + 8 + 4)


Given N=4, and the b(F) terms, and using a(F) = 2^F - b(F) we can calculate the a(F) terms:

a(F) terms, starting at F=1: 0, 0, 0, 1, 3, 8, 20, 48, 111, ...
In this list of terms, we can see that a(4) = 1, a(5) = 3, a(6) = 8, etc. Put another way, the number of permutations with 4+ heads in a row in 4 flips is 1. The number of permutations with 4+ heads in a row in 5 flips is 3. And, the number of permutations with 4+ heads in a row in 6 flips is 8. Given that, we can determine the probability by dividing the number of permutations for a specific number of flips by the total number of possible permutations (i.e. 2^F).

To summarize, there are a(F) permutations with N+ heads in a row for F flips. And the probability is a(F)/2^F. Here, N+ means N or more.


Expected Average Longest Streak Calculator... and 54.8%
The expected average longest streak (of heads or of tails) is shown in the coin flip statistics box just under the flippable coin. It is also given in the form of a calculator where you enter the number of coin flips and click the "Compute" button. Note that this value is exact for flips of 40 or less. For flips greater than 40, the value is approximate and so is rounded to 2 decimal places. It appears to be accurate to 2 decimal places.

In this calculator you can enter a flip value of up to 100 digits long.

What do we mean by "Longest Streak"? Well, if you flip a coin long enough, you will see multiple streaks. For example, say you flipped a coin 8 times with the following result: HTHHTHHH. Notice that it starts off with a streak of 1 heads (that ends in a tail). And then there is a streak of 2 heads (that ends in a tail), and finally it ends with a streak of 3 heads. For this sequence of flips, the longest streak is 3.

When I compared the data I had calculated (mentioned earlier above) with the results of this streak calculator I discovered another interesting convergence. As the minimum number of heads in a row increases, it appears that the percentage that matches the expected average longest streak approaches 54.8%.

You can see an example of this by going to the 'Coin Toss Streak Probability Calculator' and entering "20" for the minimum number of heads in a row, entering "54.8" for the probability percentage and clicking "Compute." This should give you a value of 1,665,294 for the number of coin flips required. Then, take this number of flips and enter it as the coin flips in the 'Expected Average Longest Streak Calculator' and click the "Compute" button. It should give you a value of "20" for the average streak length for that many flips! Try it for other values of the minimum number of heads in a row (less than 21 so that you can enter the probability percentage as 54.8%) and you should see the same thing.


And finally, there is a "Buy me a coffee" button. Clicking this takes you to a page where you can contribute toward the continuance of this website and my creative endeavors. Please consider donating. Thanks.

iOS Devices

You can add this Coin Toss web app to your iOS device:
1) Go to www.artbylogic/math/coinToss/coinToss.htm in your Safari browser.
2) Tap the Share button (at the bottom of the Safari screen for the iPhone, at the top for iPad)
3) Tap the icon labeled "Add to Home Screen"
4) Tap the "Add" button in the upper right hand corner of the dialog
You can now launch the Coin Toss app from its icon on your iOS device.

Android

You can pin the Coin Toss web app to your Android device:
1) Go to www.artbylogic/math/coinToss/coinToss.htm in your browser.
2) Click the Menu button. Then add the page to your bookmarks.
3) Open your bookmarks using the menu button. Find the new bookmark you just added. Press down and hold on the bookmark until you see an action menu.
4) Select "Add to homescreen" from the action menu.
The bookmark is now pinned to the homescreen for easy access.

Enjoy!
Visit www.artbylogic.com

T67350f6320c4723ea13b1f1ce1299dbd2ecd54475e33b61cb4a5c22e74f062e