Write algorithm for biased toss of a coin
Let $\xi$ be a random variable uniformly distribuited in $[0,1]$ and $t$ a real value in $(0,1)$, consider the function

$$
Y(\xi;t) = \begin{cases}
1 &amp; \xi &lt; t \\
0 &amp; \text{otherwise}
\end{cases}
$$

Which is a discrete random variable therefore

$$
p_Y(y) = (1-t) \delta(y) + t \delta(y - 1)
$$

This means that if pick a random number in $[0,1]$ and you later compute $Y$, this $Y$ will correspond to a randomly picked value in $\left\{0,1\right\}$, but biased accordingly to $t$. If you use @kngtu pseudocode, it's equivalent to define the distribution above where $t = 0.67$.