Probability of consecutive same faces in coin flip

For the discussion of math. Duh.

Moderators: gmalivuk, Moderators General, Prelates

>-)
Posts: 527
Joined: Tue Apr 24, 2012 1:10 am UTC

Probability of consecutive same faces in coin flip

I would like to know, for a coin, or any other mechanism that is completely random and generates two possible outcomes, what is the chance that you will get 'a' amount of the same outcomes 'b' times in a row when the device makes 'n' amount of random flips. So like, if a coin is flipped randomly 'n' times, what is the probability that you would get 'a' heads or tails in a row 'b' times in the entire sequence?

The best I can do right now is just figure out the probability that 'a' heads or tails will happen in a row in a sequence of 'n' flips. And that would be 1-((a-1)2-1/(a-1)2)(n-a+1)?

I tried to do something like (1-((a-1)2-1/(a-1)2)(n-a+1))b , but that didn't work because it made no sense when i plugged some numbers in (for example i somehow got about 20% chance that i could have 5, 5 heads/tails in a row in 20 flips.

Ben-oni
Posts: 278
Joined: Mon Sep 26, 2011 4:56 am UTC

Re: Probability of consecutive same faces in coin flip

You may have to clarify the question.

For instance, if you get (a+1) of the same result in a row, does that count? If so, does it count twice?

>-)
Posts: 527
Joined: Tue Apr 24, 2012 1:10 am UTC

Re: Probability of consecutive same faces in coin flip

I guess, no, it wouldn't count more than once.

OverBored
Posts: 284
Joined: Mon Dec 10, 2007 7:39 pm UTC

Re: Probability of consecutive same faces in coin flip

Would 2a in a row count twice? Or do you demand that sequences are separated by an opposite result?

Are we just counting sequences of one type, or both simultaneously? e.g a = 2: HHTT, is that a count of 2 or 1?
G4!!

Grob FTW,

Hello. Smithers. You're. Quite good. At. Turning. Me. On.

>-)
Posts: 527
Joined: Tue Apr 24, 2012 1:10 am UTC

Re: Probability of consecutive same faces in coin flip

HHHHHHHH would be 1 sequence of 8 h's and nothing else.

Not completely sure what you mean with the second one, but HHTT would be 2 different strings of 2 outcomes.

Snark
Posts: 425
Joined: Mon Feb 27, 2012 3:22 pm UTC

Re: Probability of consecutive same faces in coin flip

Not sure how to tackle this mathematically, but it shouldn't be too difficult to program a brute force search for the solution with a smallish N. And you can use random sampling if N gets too large.

For N = 20 and A = 5, my brute force search program takes ~20 seconds and gives

Code: Select all

`75.0129699707  percent chance of 0 sequences of 5 heads22.8675842285  percent chance of 1 sequences of 5 heads2.06680297852  percent chance of 2 sequences of 5 heads0.052547454834  percent chance of 3 sequences of 5 heads9.53674316406e-05  percent chance of 4 sequences of 5 heads`

For N = 20 and A = 5, a sample size of 100,000, and a run time of ~6 seconds, my random sampling program gives

Code: Select all

`75.033  percent chance of 0 sequences of 5 heads22.837  percent chance of 1 sequences of 5 heads2.084  percent chance of 2 sequences of 5 heads0.046  percent chance of 3 sequences of 5 heads0.0  percent chance of 4 sequences of 5 heads`

Which is pretty close.

I assumed that 6 A's count as a single sequence but 10 A's count as two sequences.

If you're looking for a mathematical answer, you can obviously ignore this post (unless you want to double-check your formulas if you obtain any). If you just want an answer, I can post the source code as well (though it's not difficult to figure out).
Dashboard Confessional wrote:I want to give you whatever you need. What is it you need? Is it within me?

Avatar by Matt

Timefly
Posts: 56
Joined: Sun Nov 14, 2010 7:30 pm UTC

Re: Probability of consecutive same faces in coin flip

Assuming that HHHH counts as 2 sets of 2 heads in a row.

Then the chance of getting at least 'a' heads in a row 'b' times in a sample of 'n' trials is given by the function p(a,b,n) = ((n-b)!/n!)*0.5^(ab)

OverBored
Posts: 284
Joined: Mon Dec 10, 2007 7:39 pm UTC

Re: Probability of consecutive same faces in coin flip

But, consider n = 3, b = a = 2
Clearly impossible since 2 strings of length 2 require at least 4 bits in order to happen, but your formula gives 1/96,

In fact, for fixed a,b, your formula gives a decreasing probability as n increases, which is absurd.
G4!!

Grob FTW,

Hello. Smithers. You're. Quite good. At. Turning. Me. On.