Calculating exact occurrences of a probability tree I am working on a simple slot machine for a school project and could do with some pointers on where to start. Please note, I am not asking for the answer just the area I should be looking in :-)
Every game of the slot machine will start with a random number of initial spins either, 5,6,10,15. For simplicity lets just look at 5.
Each of the 5 spins has a chance of awarding more spins in the same game. A simplified chance table looks like

No extra spins 90%
Extra 2 spins 5%
Extra 3 spins 2%
Extra 5 spins 2%
Extra 7 spins 1%

Is there a way where I can calculate the chance of spinning exactly n spins? Obviously exactly 5 spins is 0.9^5. However I cannot see how to calculate exactly 8 spins because there are multiple different paths that cover 8. I know I can use a probability tree for this but I imagine it will soon become infeasibly large to draw. Maybe it's possible using markov chains?
Thanks
 A: I would use a generating function (but see my comment below in the—well, comments).  I'm assuming that the extra spins are themselves capable of yielding extra spins.  Let's take a simpler case where there are either no extra spins with probability $0.9$, or one extra spin with probability $0.1$.  Then the generating function for a single initial spin is
$$
F(z) = 0.9z+0.1zF(z)
$$
The powers of $z$ represent the number of spins, and the coefficients represent the associated probability.  The $0.9z$ thus tells you that there is a $0.9$ probability of getting a single spin ($z = z^1$), whereas the $0.1zF(z)$ tells you that there's a $0.1$ probability of getting the single spin plus the results of the extra spin, which is back to $F(z)$ again.  (Remember that in a generating function, you represent extra spins by additional powers of $z$, so combining two results is equivalent to multiplication, not addition.)
If you solve the above equation for $F(z)$ in terms of $z$, you get
$$
F(z)(1-0.1z) = 0.9z
$$
or
$$
F(z) = \frac{0.9z}{1-0.1z}
$$
You may recognize this as the expression for a geometric series, with first term $0.9z$ and constant ratio $0.1z$.  That is, the expansion of $F(z)$ is
$$
F(z) = 0.9z + 0.09z^2 + 0.009z^3 + \cdots
$$
In other words, there's a $0.9$ probability of getting only the one initial spin; a $0.09$ probability of getting a total of two spins; a $0.009$ probability of getting a total of three spins; and so on.  You can verify this by simulation, if you like.
As it happens, the generating function for $k$ initial spins is quite simple; it is merely $[F(z)]^k$.
Now, in your case, you would have as the result of a single initial spin
$$
F(z) = 0.9z + 0.05z[F(z)]^2 + 0.02z[F(z)]^3 + 0.02z[F(z)]^5 + 0.01z[F(z)]^7
$$
Solving for $F(z)$ in this case is probably not possible analytically, so you would have to resort to numerical methods to obtain the coefficients of $z$ in $F(z)$.  Once you did that, obtaining the coefficients of $z$ in $[F(z)]^k$ would be relatively straightforward (again numerically).
