Probability of Same Consecutive Digits Two / Three / Four Times

combinatoricsprobability

For work I have a device that generates a 'random' 8 digit code, with digits ranging from 0-9. The code can start with 0. For example:

01234567
76925951
93508862

I am looking for the probability of generating a code that has:

A) The same digit consecutively at least two times (like 84316635)
B) The same digit consecutively at least three times (like 44468941)
C) The same digit consecutively at least four times (like 23577776)

It doesn't matter if the consecutive digits appear more often than once, or in a longer string than required. It qualifies as soon as it meets the requirements at least once.

These are three separate questions, though obviously related. I can generate some code that gives me the answers, but I'm looking for the calculations without running the experiment. If possible, I'm looking for a single formula to answer all three questions, with variable X being number of consecutive same digits required.

Best Answer

A) The probability that no two consecutive digits are the same is $0.9^7$. (The first digit can be anything. The second digit can be anything except the first digit. The third digit can be anything except the second digit, and so on.) So the probability of at least one pair of consecutive digits is $1 - 0.9^7$.

B) There are six possible starting positions for the first occurrence of the digit that appears three times in a row. The probability of three digits the same in a row is $0.01$ (first digit is anything, second and third are the same with probabiliy $0.1$ each). After the three of a kind appears, we don't care what happens. So the probability is

$$\sum_{k=0}^5 0.9^k(0.01).$$

C) Same thing as above, except there are five places for the first occurrence of the digit that appears four times in a row, with probability $0.001$:

$$\sum_{k=0}^4 0.9^k(0.001).$$