<s>[INST] Urn problem with random halting Consider an urn with $r$ red and $b$ black balls in it. We start drawing balls (without replacement) from it with following rules:

*

*If the drawn ball is red, we stop the draw with probability $p$. Conversely, we continue the draw with probability $1-p$.


*If the drawn ball is black, we stop the draw.
What is the expected number of drawn balls?
For $p=0$ the question was already solved here. It doesn't seem clear to me how to incorporate the random stop into the solution of $p=0$ case.
 [/INST] You will draw the first ball with probability $1.$
The probability that you stop after drawing the first ball is
$$ \frac{b + pr}{b + r}. $$
The probability that you draw the second ball is
$$ 1 - \frac{b + pr}{b + r} = \frac{qr}{b + r}.$$
The probability that you draw the $n$th ball,
given that you drew the $(n-1)$st ball, is
$$
1 - \frac{b + p(r + 2 - n)}{b + r + 2 - n} = \frac{q(r + 2 - n)}{b + r + 2 - n}.
$$
So if $N$ is the total number of balls drawn,
\begin{align}
\mathbb P(N\geq1) &= 1, \\
\mathbb P(N\geq2) &= \frac{qr}{b + r}, \\
\mathbb P(N\geq3) &= \frac{qr}{b + r} \cdot \frac{q(r - 1)}{b + r - 1}, \\
\mathbb P(N\geq4) &= \frac{qr}{b + r} \cdot \frac{q(r - 1)}{b + r - 1}
               \cdot \frac{q(r - 2)}{b + r - 2}, \\
\mathbb P(N\geq k) &= \frac{qr}{b + r} \cdot \frac{q(r - 1)}{b + r - 1}
               \cdots \frac{q(r + 2 - k)}{b + r + 2 - k}, \\
\mathbb P(N\geq k + 1) &= \frac{qr}{b + r} \cdot \frac{q(r - 1)}{b + r - 1}
                  \cdots \frac{q(r + 1 - k)}{b + r + 1 - k}, \\
\mathbb P(N\geq r + 1) &= \frac{qr}{b + r} \cdot \frac{q(r - 1)}{b + r - 1}
                  \cdots \frac{q}{b + 1}, \\
\mathbb P(N\geq m) &= 0 \quad\text{if}\quad m \geq r + 2.
\end{align}
The expectation of $N$ is
$$
\mathbb E(N) = \sum_{k=1}^{r+1} \mathbb P(N \geq k).
$$
We can write the probabilities a little more compactly in one of the following forms:
$$
P(N \geq k + 1)
 = \frac{r!\, (b+r-k)!\, q^k}{(r-k)!\,(b + r)!}
 = \frac{\displaystyle \binom rk q^k}{\displaystyle \binom{b + r}k}
 = \frac{r^{(k)} q^k}{(b + r)^{(k)}}
$$
where $a^{(k)} = a(a-1)(a-2)\cdot(a-k+1)$ is the falling factorial.
So for example, substituting $k = j + 1$ in the formula for $\mathbb E(N)$
above, we can write
$$
\mathbb E(N) = \sum_{j=0}^r \mathbb P(N \geq j + 1)
= \sum_{j=0}^r \frac{r!\, (b+r-j)!\, q^j}{(r-j)!\,(b + r)!},
$$
but I have not been able to simplify this or any of the other forms further.
</s>