[Request] How to calculate the probability of characters appearing in a string by chance?
Let's say I have 12 random characters (a-z, A-Z, 0-9), what is the probability that all will appear in a random string of 280 characters long by chance?
Is it possible to calculate thr probability if the string is only made up of English words?
Whats the probability that 11 of the characters appear and one specific one does not?
Posted Sep 17, 2020, 10:06 PM UTC
It's a pretty good approximation, since there are lots of possible characters and lots of places in the string, to say that the probability of each character appearing in a given place is independent of the others. (In reality this isn't true, since only one of them can appear in any given place, but I'm too dumb to figure out a fully accurate formula.) So for each place, there's a 61/62 chance that you won't get a given character. Raise that to the 280th, and you have the probability that the character will never appear: 1.05%. Subtract that from one, and you get the probability that a given character will appear at least once. Raise that to the 12th, and you get the approximate probability that all 12 will appear at least once. This gives 88.1%.
If the string is made of English words, that makes a lot of things much harder. Some letters are more common than others, meaning it depends which 12 characters you want, and also means my approximation is no longer valid.
Your last question is easy, assuming a random string. Just do the formula above, replace 12 with 11, and then multiply by 1.05% for the last character, giving 0.938%. I assume by "one specific one" you mean you choose it in advance. If that's not what you meant, and it counts no matter which of the 12 letters is missing, then just multiply the answer I gave by 12, giving 11.3%.
Exactly what I was looking for, thanks!!