General ideas are from here and herehere. #R code
You first need to simulate a vector of uncorrelated Gaussian random variables, $\bf Z $
NVariables=5 VariableLen=1000 Z=matrix(rnorm(NVariables*VariableLen), ncol=NVariables)
Create covariance matrix $\Sigma$. Let all variables be correlated with neighbor as 0.5.
Sigma=matrix(data=0, ncol=NVariables-1,nrow=NVariables-1) diag(Sigma)<-0.5 Sigma=cbind(matrix(data=0,nrow=NVariables-1),Sigma) Sigma=rbind(Sigma,matrix(data=0,ncol=NVariables)) diag(Sigma)<-1
Find a square root of $\Sigma$. Cholesky decomposition is common choice
C=chol(Sigma)
To obtain random variables with given correlation matrix $\Sigma$ multiply $\bf C$ and $\bf Z$
Y=Z%*%C
Use inverse CDF method to obtain any distribution You wish. Here it is lognormal
Ylog=qlnorm(pnorm(Y))
Correlation Matrix
[,1] [,2] [,3] [,4] [,5]
[1,] 1.00000000 0.52817152 -0.01887624 -0.07113405 -0.05551355
[2,] 0.52817152 1.00000000 0.49392903 -0.03233261 -0.01504632
[3,] -0.01887624 0.49392903 1.00000000 0.50604908 0.04029076
[4,] -0.07113405 -0.03233261 0.50604908 1.00000000 0.49000229
[5,] -0.05551355 -0.01504632 0.04029076 0.49000229 1.00000000