Simulation of random variables
We have access to a sequence of independent $U[0,1]$ random variables $U_1, U_2, \ldots, U_n$, and we want to simulate independent random variables $(X_1, X_2, \ldots, X_n)$ having a given distribution.
Suppose our desired density function is $f$ in an open interval $I$. Then the distribution function $F(x) = \int_{-\infty}^{x} f(y) dy$ is an increasing map from $I$ to $(0,1)$. Let the quantile function be $$ \begin{align*} G(u) = \inf\sb{x\in\R}{u\leq F(x)}. \end{align*} $$ (When $f$ is positive everywhere, $G=F\inv$.) Note that for all $x\in\R, u\in(0,1)$, $$ \begin{align*} G(u) \leq x \iff u \leq F(x). \end{align*} $$ Then when we have $U\sim U[0,1]$ and let $X=G(U)$, we have $$ \begin{align*} \prob(X\leq x) = \prob(G(U)\leq x) = \prob(U\leq F(x)) = F(x) \end{align*} $$ so $X$ has a distribution function $F_X$.
To simulate $X\sim N(0,1)$, we take $U,V\sim U[0,1]$ and set $$ \begin{align*} \Theta = 2\pi U, \quad R = \sqrt{-2\log V} \implies V = e^{-R^2/2}, \quad \Theta\sim U[0,2\pi]. \end{align*} $$ Then $X=R\cos\Theta$ and $Y=R\sin\Theta$ are independent $N(0,1)$ random variables. (Derivation)
To simulate $\v U\sim U([0,1]^d)$, we take $\v U = (\bar U_1, \bar U_2, \ldots, \bar U_d)$ where $\bar U_i \sim U[0,1]$ are independent.
For some $A\subseteq [0,1]^d$, to simulate a random variable $\v X$ in $[0,1]^d$ having density $$ \begin{align*} f(\v x) = \frac{1_A(\v x)}{|A|}, \end{align*} $$ take $\v U_1,\v U_2,\ldots$ independent $U([0,1]^d)$ random variables and $\v X$ to be the first of those which land in $A$, i.e. reject the others: $$ \begin{align*} \v X = \v U_N, \quad N=\min\sb{n\geq 1}{\v U_n \in A}. \end{align*} $$ (Derivation)
In general to simulate $\v X$ having a bounded density $f$ in $[0,1]^d$, let $f(\v x)\leq \lambda$ for all $\v x$. We'll apply the same technique as above to $[0,1]^{d+1}$:
Take $\v U_1, \v U_2, \ldots \sim U([0,1]^d)$ and $V_1,V_2,\ldots\sim U[0,1]$ all independent random variables, and $\v X$ to be the the first $\v U_n$ such that $V_n\leq f(\v U_n)/\lambda$: $$ \begin{align*} \v X = \v U_n, \quad N = \min\sb{n\geq 1}{V_n \leq f(\v U_n)/\lambda}. \end{align*} $$ (Derivation)
https://www.geogebra.org/calculator/gtjdw2kc
See the general formulation.