finding a generating function of a gambler question 
*

*Suppose a gambler starts with one dollar and plays a game in which he or she wins one dollar with probability $p$ and loses one dollar with probability $1 - p$.

*Let $f_{n}$ be the probability that he or she first becomes broke at time $n$ for $n = 0, 1, 2\ldots$.

*Find a generating function for these probabilities.

Is it binomial distribution $?$ and then use the $\operatorname{mx}\left(s\right) = rx\left(\mathrm{e}^{s}\right)$ of the binomial distribution $?$.
Help$\ldots!$.
I am correcting my quiz.
 A: Note that the first time the gambler goes broke must be after an odd number of bets, so $f_0=f_2=f_4=\ldots=0$. Let $C_n$ be the number of possible sequences of $2n+1$ bet results such that the gambler first becomes broke after $2n+1$ bets. There will necessarily be $n$ wins and $n+1$ losses for the gambler. The constants $C_n$ are called that Catalan numbers. There is a closed form expression for them, but we will not need it. The probability that the gambler first goes broke after $2n+1$ bets is $f_{2n+1}=C_np^n(1-p)^{n+1}$.
We form the generating function
$$
g(x):=\sum_{n\geq 0}C_nx^n.
$$
We have
$$
(1-p)\cdot x\cdot g\left(p(1-p)x^2\right)=\sum_{n\geq 0}C_np^n(1-p)^{n+1}x^{2n+1}=\sum_{n\geq0}f_nx^n.
$$
Now, if $p<\frac{1}{2}$, then the Gambler's expected earning from each bet is negative, and the gambler MUST eventually go broke. This means that for $p<\frac{1}{2}$,
$$
(1-p)\cdot g(p(1-p))=1,
$$
or equivalently,
$$
g(p(1-p))=\frac{1}{1-p}.
$$
Suppose that $p<\frac{1}{2}$, and write $y=p(1-p)$. Solving for $p$ (using the quadratic formula) gives
$$
p=\frac{1-\sqrt{1-4y}}{2},
$$
so that
$$
g(y)=\frac{1}{1-p}=\frac{1-\sqrt{1-4y}}{2y}
$$
for $y$ sufficiently small. Finally, setting $y=p(1-p)x^2$, we get
$$
\begin{eqnarray*}
\sum_{n\geq 0}f_nx^n&=&(1-p)\cdot x\cdot g\left(p(1-p)x^2\right)\\
&=&(1-p)x\frac{1-\sqrt{1-4p(1-p)x^2}}{2p(1-p)x^2}\\
&=&\frac{1-\sqrt{1-4p(1-p)x^2}}{2px}.
\end{eqnarray*}
$$
