normal_dataset, a Fortran90 code which creates a multivariate normal random dataset and writes it to a file.

The multivariate normal distribution for the M dimensional vector X has the form:

        pdf(X) = (2*pi*det(A))^(-M/2) * exp(-0.5*(X-MU)'*inverse(A)*(X-MU))
where MU is the mean vector, and A is a symmetric positive definite (SPD) matrix called the variance-covariance matrix.

To create X, an MxN matrix containing N samples from this distribution, it is only necessary to

  1. create an MxN vector Y, each of whose elements is a sample of the 1-dimensional normal distribution with mean 0 and variance 1;
  2. determine the upper triangular Cholesky factor R of the matrix A, so that A = R' * R;
  3. compute X = MU + R' * Y.


normal_dataset m n seed mu a
where The data is written to the file normal_m_n.txt.

Although m, n, and seed may be entered on the command line, it probably makes more sense to enter the vector mu and the matrix a interactively.


The information on this web page is distributed under the MIT license.


normal_dataset is available in a C++ version and a Fortran90 version and a MATLAB version and an Octave version and a Python version.

Related Data and Programs:


normal, a Fortran90 code which computes normally distributed pseudorandom values.


  1. Paul Bratley, Bennett Fox, Linus Schrage,
    A Guide to Simulation,
    Springer Verlag, pages 201-202, 1983.
  2. Donald Knuth,
    The Art of Computer Programming,
    Volume 2: Seminumerical Algorithms,
    Addison Wesley, 1969.

Source Code:

Last revised on 15 May 2024.