%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ------------------------------------------------------------------------
% Generating Normal Pseudo-random Numbers ********************************
% ------------------------------------------------------------------------
% File Name:      NormalPseudo-randomNumber.tex
% Submitted:      Dr. Eric Suess,Statistics 6501,Winter 2002
% Submitted Date: January 14th, 2002
% Accepted Date:  January 14th, 2002
% ------------------------------------------------------------------------
% This is a first draft of the handout "Generating Normal Pseudo-random
% Numbers" in LaTeX.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass[12]{report}

\usepackage{latexsym}
\usepackage[centertags]{amsmath}
\usepackage{amsfonts}
\usepackage{newlfont}
%\usepackage{graphicx,fullpage,subfigure,pstricks}

\setlength{\oddsidemargin}{-0.4cm}

\setlength{\evensidemargin}{0cm}

\setlength{\topmargin}{-0.75cm}

\setlength{\textheight}{8.9in}

\setlength{\textwidth}{6.5in}

\renewcommand{\baselinestretch}{1}

\setlength{\parskip}{3mm}

\setlength{\parindent}{0mm} % indented paragraphs just don't

%\pagestyle{plain}

\begin{document}

\pagestyle{myheadings} \markright{Statistics 6501, Winter 2002}

\large
\begin{center}
\textbf{Generating Normal Pseudo-random Numbers}
\end{center}

\normalsize
\textbf{Box-Muller Method:}

How to simulate two independent Normal random variables with mean
$\mu$ and variance $\sigma^2$?

Generating $U, V$ independent $UNIF(0,1)$ random values.

Then

\large
\begin{center}
\begin{tabular}{cc}
$W=cos(2\pi U)\sqrt{-2ln(V)}$ & and \hspace{0.1in} $X=sin(2\pi
U)\sqrt{-2ln(V)}$
\end{tabular}
\end{center}
\normalsize

are such that $W$ and $X$ are independent $Normal(0,1)$ values.

To get $Y$ and $Z$ independent $N(\mu,\sigma^2)$ calculate

\large
\begin{center}
\begin{tabular}{cc}
$Y=\mu+\sigma W$ & and \hspace{0.1in} $Z=\mu+\sigma X$
\end{tabular}
\end{center}
\normalsize

The following Pascal code implements the Box-Muller Method.

\begin{verbatim}
FUNCTION Random2 : Real;
{ This function checks if the random number we take the natural log  }
{ of is very small.  If so, then we set it equal to something small. }
VAR
      x : Real;
BEGIN
      x := Random;
      IF x <= 0.0001 THEN
            Random2 := 0.0001
      ELSE
            Random2 := x;
END;

PROCEDURE Normal(VAR W, X : REAL);
VAR
      T1, T2 : REAL;
BEGIN
      T1 := 2*Pi*Random;
      T2 := sqrt(-2.0*ln(Random2));
      W := cos(T1)*T2;               { Note W and X are independent }
      X := sin(T1)*T2;               { standard Normals.            }

END;
\end{verbatim}

\end{document}
% ------------------------------------------------------------------------
