= Solution
Treat the supplied uniform variates as <independent> $U(0,1)$ draws, as required for Monte Carlo simulation. Use $n$ of them and return
$$
\boxed{X=\sum_{j=1}^n\mathbf1_{\{U_j\leq p\}}.}
$$
Each indicator has a <Bernoulli distribution> of parameter $p$, and the indicators are <independent>. For any subset of $r$ successes the <probability> is $p^r(1-p)^{n-r}$; there are $\binom nr$ such subsets. Thus $\mathbb P(X=r)=\binom nrp^r(1-p)^{n-r}$, the <binomial distribution>. The construction includes the cases $p=0,1$ and $n=0$.
Back to article page