Generate Correlated Normal Random Variables
If you need to generate $n$ correlated Gaussian distributed random variables $$ \bf Y \sim \mathcal N(\bf \mu, \Sigma) $$ where $\textbf{Y} = (Y_1,\dots,Y_n)$ is the vector you want to simulate, $\mu =(\mu_1,\dots, \mu_n)$ the vector of means and $\Sigma$ the given covariance matrix,
- you first need to simulate a vector of uncorrelated Gaussian random variables, $\bf Z $
- then find a square root of $\Sigma$, i.e. a matrix $\bf C$ such that $\bf C \bf C^\intercal = \Sigma$.
Your target vector is given by $$ \bf Y = \bf \mu + \bf C \bf Z. $$
A popular choice to calculate $\bf C$ is the Cholesky decomposition.
$\newcommand{\Cov}{\mathrm{Cov}}$
I wanted to add that comment to the previous answer :
Why is it true ?
Define $Y = \mu + C Z$, and recall that each component of $Z$ is i.i.d. normal :
$$ \Cov( Y ) = \Cov(CZ + \mu ) = \Cov(CZ ) = C \cdot \Cov (Z) \cdot C^T = C I C^T = \Sigma $$ which is the desired result : $$ \implies Y \sim \mathcal N (\mu, \Sigma) $$