An almost surely finite time game of coin toss where you win with probability $p$
Let $x_1,x_2,x_3,\ldots$ be the coin tosses, and let $p=0.y_1y_2y_3\ldots$ be the binary expansion of $p$. Halt once either of the following events happens:

$x_1=y_1,\ldots,x_{n-1}=y_{n-1}$ but $x_n &lt; y_n$. In that case, declare a win.
$x_1=y_1,\ldots,x_{n-1}=y_{n-1}$ but $x_n &gt; y_n$. In that case, declare a loss.

The game halts with probability $1$, since at any step it has a probability of $1/2$ to end. Let us now compute the probability of winning at the $n$'th step. If $y_n = 0$ then this event has probability $0$, and if $y_n = 1$ then it has probability $2^{-n}$. In total, the probability to win at the $n$'th step is $y_n 2^{-n}$. Since these events are disjoint, we deduce that the winning probability is
$$
\sum_{n=1}^\infty y_n 2^{-n} = p.
$$
What is happening here? We can imagine the coin being tossed infinitely many times, generating a value $q \in [0,1]$ whose binary expansion is $0.x_1x_2x_3\ldots \in [0,1]$. Clearly, $q$ is uniformly distributed in $[0,1]$. The game is a win if $q &lt; p$ and a loss if $q &gt; p$ (the probability that $q = p$ is zero). We can halt the game without generating all digits of $q$ if a prefix of its binary expansion suffices to determine that $q &lt; p$ or that $q &gt; p$.