# Probability: pick a ball after a coin toss

An urn contains $$N$$ balls, $$K$$ balls of which are red. You toss a coin that has a probability $$p$$ of landing heads. If the coin lands heads, you pick a ball from the urn at random, without replacement. If the coin lands tails, you do nothing. You repeat the coin toss for $$n$$ times in total.

Let $$x$$ be the number of red balls that you picked after $$n$$ coin tosses. What is the expected value and probability distribution of $$x$$?

Without the coin toss condition (or $$p=1$$), $$x$$ follows a hypergeometric distribution. I'm having trouble with incorporating the coin toss however.

We can rework the scenario so all the coin-tosses happen before the drawing from the Urn. For the coin landing heads $$k$$ times the probability is just
$$P_{1,n}(k)={n \choose k}p^k(p-1)^{n-k}$$ (Binomial distribution). So if the probability to get $$a$$ red Balls after picking $$b$$ Balls from the Urn (without the coin) is $$P_{2,b}(a)$$, the probability (with cointoss) of picking $$x$$ red balls is
$$P(x)=\sum_{i=x}^n P_{1,n}(i) \cdot P_{2,i}(x)$$
. You have the possibility for each amount of heads-coin-tosses greater or equal to $$x$$ to pick $$x$$ red balls, so you just summ over all the possible amounts of coin tosses. That would be explicit (with the probability of a event in a hypergeometric distribution from wikipedia)
$$P(x) = \sum_{i=x}^n p^i (1-p)^{(n-i)} {n \choose i} \frac{{K \choose x} {N-K \choose i-x}} {N \choose i}$$