Solution (source code)

= Solution

Generate <independent and identically distributed random variables> $X_1,\ldots,X_n$ with <probability density function> $p$, evaluate $\phi(X_i)$ for each draw, and return the <Monte Carlo estimator>
$$
\boxed{\widehat\theta_n^{\mathrm{MC}}=\frac1n\sum_{i=1}^n\phi(X_i).}
$$
<Linearity of expectation> makes this an <unbiased estimator>: $\mathbb E\widehat\theta_n^{\mathrm{MC}}=\theta$. Independence and the specified <variance> give $\operatorname{Var}(\widehat\theta_n^{\mathrm{MC}})=1/n$. Its <Monte Carlo standard error> is therefore $n^{-1/2}$, and the <strong law of large numbers> gives convergence to $\theta$ <almost surely>.