What's the probability of a set of only three digits appearing in a random 9 digit set? I'd like to know the method for correctly calculating the probability of a random sequence of $9$ numbers only containing $3$ unique, different numbers. For the purpose of this question: there are 10 numbers $0,1,2,3,4,5,6,7,8,9$
i.e. the probability of this: $123123123$ - for all unique combinations of $3$ digits (e.g $071$ in $071717717$)
My initial instinct is $(1/3)^9$ - is this correct?
 A: And there is the bull at red cape brute force method ... here using Mathematica:
SantasLittleDigitCounter[m_] := (j = 0;
 Do[ If[Length[Union[IntegerDigits[i, 10, m]]] == 3, j++], {i, 0, 10^m - 1}]; j)

Then:
SantasLittleDigitCounter[9]


2178000

which matches exactly the super theoretical solution derived above by Mario Carneiro.

A few minor comments:


*

*Ran this while having dinner. 

*A neater/better approach in Mathematica is usually to generate all the numbers we want to test in one go (say lis = Range[$0$, $10^9-1$]), and then test them all in one go, using faster functional approaches such as Map rather than the more old-fashioned procedural Do loop-de-loop ... but because the number of terms we have to test is so large (a billion), the memory requirements of generating them all in one go is a bit messy ... so went back to just using good old Do. I suppose one could parallel-optimise this, if desired.

*The original poster has noted that numbers like 21 count as a 3-digit hit, because it is represented as the 9 digit {0,0,0,0,0,0,0,2,1}. This is the reason for using the form IntegerDigits[i, 10, m] ... which pads integer i (in base 10) with zeroes to fill $m=9$ slots.
A: There are two problems with your solution.  First, there are ${9 \choose 3}$ ways to choose which three digits you pick, so you have to multiply by that.  Second, if the digits are $123$, you have counted sets like $111111111$ and $121212121$ that have only one or two different digits respectively.  It seems you do not want to count them at all, and in fact you have counted them many times.
The easiest way is to start with ${9 \choose 3}3^9$ as the count of digit strings, then subtract the ones with just one or just two digits.  The strings with just one digit have been counted ${8 \choose 2}$ times, and there are $9$ of them.  The ones with exactly two digits have been counted $7$ times each and there are ${9 \choose 2}(2^9-2)$ of them.  So the final count is ${9 \choose 3}3^9-9{8 \choose 2}-7{9 \choose 2}(2^9-2)$ and the probability comes from dividing this by $9^9$
A: From the Twelvefold way, the number of surjective functions from a set of size $n$ to one of size $x$ is $x!\{{n\atop x}\}$, where $\{{n\atop x}\}$ is the Stirling number of the second kind. Here $n=9$ and $x=3$, and this represents the number of $9$-digit numbers containing $3$ (specified) integers. There are ${10\choose 3}$ possibilities of which integers to allow in the number (assuming base 10), so the total probability is
$$P=\frac{3!}{10^9}\left\{{9\atop 3}\right\}{10\choose 3}=\frac{6\cdot3025\cdot120}{1000000000}=\frac{2178000}{1000000000}=0.2178\%$$
which is a bit more than the $3^{-9}\approx.005\%$ originally predicted.
Edit: due to some ambiguities in the OP, I'm also listing the same results as above where the base alphabet only contains $9$ symbols (say $\{0,1,2,3,4,5,6,7,8\}$), per Ross Millikan's analysis. Then we have
$$P=\frac{3!}{9^9}\left\{{9\atop 3}\right\}{9\choose 3}=\frac{6\cdot3025\cdot84}{387420489}=\frac{1524600}{387420489}\approx0.39352\%.$$
In general, if we want to know the proportion of length $n$ strings on an alphabet of $k$ symbols which use exactly $x$ distinct symbols, the formula is $P=\frac{x!}{k^n}\left\{{n\atop x}\right\}{k\choose x}$.
