# Calculating probability of 8 letter String [closed]

Computer generate 8 string password with letters a,b,c,d,e. Each letter is chosen independently and with equal liklihood of being selected.

What is the probability that the string has 8 of the same letter?

What is the probability that there is at least one a and one b?

Can someone help me with these? I calculated the total outcomes, but I' stuck there.

## closed as off-topic by Saad, farruhota, max_zorn, Cesareo, JaviApr 18 at 10:18

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question is missing context or other details: Please provide additional context, which ideally explains why the question is relevant to you and our community. Some forms of context include: background and motivation, relevant definitions, source, possible strategies, your current progress, why the question is interesting or important, etc." – Saad, farruhota, max_zorn, Cesareo, Javi
If this question can be reworded to fit the rules in the help center, please edit the question.

## 2 Answers

The total number of the possible passwords are $$5^8=390625$$. All of these possible passwords have the same probability.

What is the probability that the string has 8 of the same letter?

It is only 5 possibility of the 390625, so the probability is $$\frac{1}{5^7}=1.28\cdot 10^{-5}$$.

What is the probability that there is at least one a and one b?

It is more complex:

1. If there is no "a" and no "b": then we have 8 character long passwords, but only from c, d and e. Thus, it is $$3^8=6561$$.
2. If there is no "a": so we have 8 character long passwords, but only from b, c, d, and e. Thus, they are $$4^8=65536$$.
3. If there is no "b": the calculation is the same.

Now, we remove from all the possibilities the cases, if there are no "a", and also the cases, if there are no "b".

But, so we removed the cases, where there are no "a" and also no "b", twice! Thus, we need to add it back.

The result is $$5^8-2\cdot 4^8+3^8$$.

Thus, the probability that we have at least one "a" and one "b", is $$\frac{5^8-2\cdot 4^8+3^8}{5^8}=\underline{\underline{0.68125184}}$$.

• Thank you! Makes so much sense? What is it was OR instead of AND, would it just be a sum of individual probabilities? – Robin Apr 18 at 2:01
• @Robin So it had been much easier, because then we should have count only the cases, if there is no "a" and no "b". So it had been $5^8-3^8$. – peterh Apr 18 at 2:05

There are $$5$$ choices for each character of the $$8$$ in the password, so $$5^8$$ possible passwords. Of those, $$5$$ are strings of the same letter (aaaaaaaa, bbbbbbbb, cccccccc, dddddddd, and eeeeeeee), so the probability that the string has only one letter is $$5/5^8=1/5^7$$.

To get passwords without a there are $$4^8$$ possibilities; to get passwords without b there are $$4^8$$ possibilities; of these, there are $$3^8$$ possibilities for passwords without a and without b. So the probability of generating a password with at least one a and one b is $$(5^8-4^8-4^8+3^8)/5^8=1-2\times0.8^8+0.6^8.$$

• So you have counted also the passwords which have a, but no b. – peterh Apr 18 at 2:45
• I agree with @peterh, it seems you've calculated the probability of at least one $a$ OR at least one $b$, not AND. – Brahadeesh Apr 18 at 3:16
• Thanks for the comments; I have edited accordingly – J. W. Tanner Apr 18 at 5:11