# Find the distribution of $Z=\min \{n: U_n \leq h(n) \}$

Let $X$ be a non-negative integer-valued random variable with probability mass function $f(k)=P(X=k)$ for $k=0,1,2,\ldots$ Define a function $h(r) = P(X=r | X \geq r)$. Let $U_i$ for $i=0,1,2,\ldots$ be a sequence of i.i.d. random variable uniformly distributed over $[0,1]$.

Find the distribution of $Z=\min \{n: U_n \leq h(n) \}$.

For every $k\geqslant0$, $P(Z=k)=P(X=k)$. Actually, this is a well known procedure to simulate any given distribution on the nonnegative integers using an i.i.d. sequence of uniform random variables on $[0,1]$.
Hint: For every $n\geqslant0$, $1-h(n)=P(X\geqslant n+1\mid X\geqslant n)=\dfrac{P(X\geqslant n+1)}{P(X\geqslant n)}$ hence, for every $k\geqslant0$, the identity $$[Z\geqslant k+1]=\bigcap_{n=0}^k[U_n\gt h(n)]$$ implies that, by independence of $(U_n)$, $$P(Z\geqslant k+1)=\prod_{n=0}^k(1-h(n))=\prod_{n=0}^k\frac{P(X\geqslant n+1)}{P(X\geqslant n)}=P(X\geqslant k+1).$$