TITLE: Probability of random integer's digits summing to 12
QUESTION [21 upvotes]: What is the probability that a random integer between 1 and 9999 will have digits that sum to 12?
As a user suggested, I could make a spreadsheet and count them, but is there a quicker way to do this?

REPLY [16 votes]: Use generating functions.  The generating function for a single digit is:
$$1 + x + \cdots + x^9 = \frac{1-x^{10}}{1-x}.$$
The generating function for the sum of four digits is the fourth power:
$$\frac{(1-x^{10})^4}{(1-x)^4} = (1-x^{10})^4 (1-x)^{-4}.$$
To solve the problem, find the coefficient of $x^{12}$.
$$(1-x^{10})^4 = 1 -4 x^{10} + 6 x^{20} - \cdots$$
So, we only need the coefficients of $x^2$ and $x^{12}$ in $(1-x)^{-4}$ using the generalized binomial theorem. These are $\binom{5}{2} = 10$ and $\binom{15}{12} = 455$. The coefficient of $x^{12}$ is therefore
$$ -4\cdot10 + 1\cdot455 = 415.$$
So the answer is $\frac{415}{9999}$.