[Math] How do find the probability that all digits will occur in a randomly created number.

probability

The title pretty much sums it up my question.

I've been working with 16 digit numbers because the random number generator I was working with spit out 16 digit numbers, but I would like to know the process for finding the probability for any given length random number which has a length greater than 9.

I brute forced the question and came up with ~7% of the time a random 16 digit number will contain all numbers between 0-9 at least once in any position.

Note I'm assuming the random number can start with 0. So, 0000000987654321 is a valid random number that contains all the digits.

Best Answer

Imagine a sequence of 16 random digits, uniformly distributed and chosen independently. What's the probability that there is no $7$ in it? The 1st digit is a non-7, and the 2nd digit is a non-7, and the 3rd digit is a non-7, etc. It's $\left(\dfrac{9}{10}\right)^{16}$. Similarly that's the probability that there is no $6$, etc.

One way to answer the whole question would be to apply the inclusion–exclusion principle:

There's no 0 or there's no 1 or there's no 2 or $\ldots\ldots$.

This is an inclusive "or".

\begin{align} & {}\qquad \Pr(\text{no $0$s or not $1$s or no $2$s or }\cdots) \\[10pt] & = \underbrace{\Pr(\text{no $0$s}) + \Pr(\text{no $1$s}) + \Pr(\text{no $2$s}) + \cdots}_\text{10 terms} \\[8pt] & \underbrace{{}- \Pr(\text{no $0$s and no $1$s}) - \Pr(\text{no $0$s and no $2$s}) - \cdots\cdots}_\text{45 terms} \\[8pt] & \underbrace{{}+ \Pr(\text{no $0$s and no $1$s and no $2$s}) + \Pr(\text{no $0$s and no $1$s and no $3$s})+ \cdots\cdots}_\text{120 terms} \\[8pt] & {} - \text{ etc., etc. } \cdots\cdots \\[12pt] & = 10\left(\frac{9}{10}\right)^{16} - 45\left(\frac{8}{10}\right)^{16} + 120\left(\frac{7}{10}\right)^{16} - \cdots\cdots \end{align}

Related Question