Probability of random integer's digits summing to 12 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?
 A: Just so GAP doesn't get left out.  Here's a GAP version to obtain the count:
Number([1..9999],n->Sum(ListOfDigits(n))=12);

which returns 415.  So, the probability is $415/9999$.
A: With PARI/GP code

Q(n)=if(n<10,n,n%10 + Q(n\10))
sum(i=1,9999,Q(i)==12)/9999

I obtain
$$\frac{415}{9999}.$$
A: The problem does not require a spreadsheet.  It does not even require paper.
The question is to count the number of integer tuples $\langle a,b,c,d\rangle$ with $a+b+c+d=12$ and $0\le a,b,c,d < 10$. We could enumerate this  by choosing $a$ and then counting the tuples $\langle b,c,d\rangle$ with $b+c+d = 12-a$, and recursing, but an easier method is available.
First, note that if we drop the $a,b,c,d < 10$ restriction, the problem is easy.  By the stars and bars method, there are $\binom{15}{12} = 455$ tuples that sum to 12.
From these 455 we need to eliminate the ones that contain $10, 11,$ or $12$.
Let $t_i$ be the number of tuples where  $a =i$ for $i\in\{10,11,12\}$.  Clearly, $t_{12} = 1$: the only tuple is $\langle 12, 0,0,0\rangle$.  For $a=11$ we need $b+c+d=1$, so exactly one of $b,c,d$ is 1 and the other two are 0, and thus $t_{11} = 3$.
For $a=10$ there are two possibilities.  Either $\{b,c,d\} = \{2,0,0\}$ or $\{b,c,d\} = \{1,1,0\}$.  In either case there are 3 tuples, so $t_{10} = 6$.
Since at most one of $a,b,c,d$ is greater than 9, the total number of tuples that contain 10, 11, or 12 is $4(t_{10}+t_{11}+t_{12}) = 40$.
Thus the total number of tuples of just 0 through 9, and the answer to the question, is 455 - 40 = 415; the probability is $\frac{415}{9999}$.
A: 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}$.
A: With Mathematica code (FROM 1 TO 9999):
Count[Map[Total, IntegerDigits[Range[9999]]], 12]


415

So: 415/9999
