function r = normal(n,mu,sigma2)
% usage: r = normal(n,mu,sigma2)
% generate vector of normal random variables
%   mu = mean
%   sigma2 = variance or var/covariance matrix 
%   
if (size(mu,2)==1) % univariate
    r = sqrt(sigma2)*randn(n,1) + mu;
else
% multivariate normal
% sigma2 = vcvar matrix
rr = chol(sigma2)';
m = size(mu,2);
id = randn(n,m);
r = ones(n,1) * mu + (rr * id')';
end
