This simulation was used as part of an assignment I made for the Rutgers probability class (summer 2015)

Counting consecutive strings in coin flips

This code helps you count consecutive strings of Heads in a sequence of coin flips. It is for assignment 4 (special) which is due in class on Monday June 15.

This uses a simple Monte Carlo approximation to estimate the probability distribution for the length of the longest consecutive sequence of Heads in a fixed number of coin flips. Let's call this random variable Y. For example, if the sequence of flips was HTHHTHHHTTHHHTTHTTTT, then the longest string of consecutive Heads is 3 [and this happens twice in this sequence] so Y=3 in this case.

This website works by simply getting the computer to flip many coins for you. Suppose for instance you want to estimate Y when the experiment is to flip a fair coin 100 times. Then the computer does this experiment for you many, many times (you specify how many times it does this by specifying the number of "experiments"). The computer then just computes and records Y for each of these experiments, and it outputs this information to you in a window.

Let me know if you're having any trouble with this. If you're curious about the code, then see the page source.

Monte Carlo coin flip simulator

Number of flips in each experiment n=
Number of experiments to run
Find the number of experiments for which Y is less than or equal to k=
Probability of H for each flip p=