Problem of generating a standard normal distribution 
The algorithm for generating a standard normal random variable $Z$ is 
Step 1. Generate $Y$ with an exponential distribution at rate 1; that
  is, generate $U$ and set $Y=-ln(U)$
Step 2. Generate $U$. If $U \le e^{-(Y-1)^2/2}$, set $|Z| = Y$;
  otherwise go back to Step 1. 
Step 3. Generate $U$. Set $Z = |Z|$ if $U \le 0.5$, set $Z = -|Z|$ if
  $U > 0.5$.
Provide an argument on showing that the above algorithm indeed leads
  to a standard normal random variable $Z$.

This is the whole question that my prof. gave us in the statistics examination. But, besides Rejection Method, he taught NOTHING about how to generate a random variable, which makes me feel so annoyed... And I REALLY have NO IDEA about it. 
Would you mind give me any hint or something similar, which I can know how to deal with it? A big thanks.
 A: This is the A/R method!
$$P(Z≤z)= P(Z≤z| Accept) = \frac {P(Z≤z,U≤e^{-\frac {(Y-1)^2}{2}})}{P(U≤e^{-\frac {(Y-1)^2}{2}})}$$ 
Now, we condition on the event {$Y=y$} to evaluate both probabilities:
$$P(U≤e^{-\frac {(Y-1)^2}{2}}) = \int_0^{\infty}P(U≤e^{-\frac {(Y-1)^2}{2}}|Y=y)f_Y(y)dy$$
$$=\int_0^{\infty}e^{-\frac {(y-1)^2}{2}}e^{-y}dy= \int_0^{\infty}e^{\frac {(-y^2-1)}{2}}dy = e^{-\frac 12}\frac {\sqrt{2\pi}}{2}$$  
from evaluating the Gaussian integral
without loss of generality, assume $z≥0$ Again, we use the same conditioning trick
$$P(Z≤z,U≤e^{-\frac {(Y-1)^2}{2}}) = P(Y≤z,U≤e^{-\frac {(Y-1)^2}{2}}|Z>0)P(Z>0) +P(-Y≤z,U≤e^{-\frac {(Y-1)^2}{2}}|Z≤0)P(Z≤0)$$
since we know {$-Y≤z$} with probability $1$ when $z≥0$
$$P(Z≤z,U≤e^{-\frac {(Y-1)^2}{2}})=\frac 12P(Y≤z,U≤e^{-\frac {(Y-1)^2}{2}}) + \frac 12P(U≤e^{-\frac {(Y-1)^2}{2}})$$
condition again: 
$$=\frac 12\int_0^zP(U≤e^{-\frac {(Y-1)^2}{2}}|Y=y)f_Y(y)dy + \frac 12\int_0^{\infty}P(U≤e^{-\frac {(Y-1)^2}{2}}|Y=y)f_Y(y)dy$$
$$=\frac 12\int_0^ze^{-\frac {(y-1)^2}{2}}e^{-y}dy + \frac 12\int_0^{\infty}e^{-\frac {(y-1)^2}{2}}e^{-y}dy = \frac 12e^{-\frac 12}\int_0^ze^{-\frac {y^2}{2}}dy + \frac 12e^{-\frac 12}\int_0^{\infty}e^{-\frac {y^2}{2}}dy = *$$
Because $e^{-\frac {y^2}{2}}$ is even,
$$* = \frac 12e^{-\frac 12}(\int_0^ze^{-\frac {y^2}{2}}dy + \int_{-\infty}^{0}e^{-\frac {y^2}{2}}dy) = \frac 12e^{-\frac 12}\int_{-\infty}^ze^{-\frac {y^2}{2}}dy$$
Put everything together...
$$P(Z≤z)= P(Z≤z| Accept) = \frac {P(Z≤z,U≤e^{-\frac {(Y-1)^2}{2}})}{P(U≤e^{-\frac {(Y-1)^2}{2}})} = \frac {\not {\frac 12}\not {e^{-\frac 12}}\int_{-\infty}^ze^{-\frac {y^2}{2}}dy}{\not {e^{-\frac 12}}\frac {\sqrt{2\pi}}{\not 2}} $$
$$= \frac {1}{\sqrt {2\pi}}\int_{-\infty}^ze^{-\frac {y^2}{2}}dy$$ 
As desired. Therefore, $Z$ is a standard Normal random variable with mean $0$ and variance $1$
The case where $z≤0$ is absolutely similar. Just note that $P(Y≤z, Accept|z≤0) = 0$
