# GNORMAL

## Purpose:

Generates a normally distributed random series.

## Syntax:

GNORMAL(length, spacing, mean, std, unscale)

length

-

An integer, the length of the output series.

spacing

-

A real, the spacing (delta x) between points.

mean

-

Optional. A real, the series mean. Defaults to 0.0.

std

-

Optional. A real, the series standard deviation where 0 < std. Defaults to 1.

unscale

-

Optional. An integer, the mean and standard deviation scaling flag.

 0 : Standard mode, scale the result to have the specified mean and standard deviation (default). 1 : Raw mode, do not scale the result. The result will have approximately the specified mean and standard deviation.

A series.

## Example:

gnormal(100, 0.01, 2.0, 3.0)

creates a 100 point, normally distributed random series of values from a population where the mean is 2.0 and the standard deviation is 3.0. The result is scaled to have an exact mean of 2.0 and an exact standard deviation of 3.0.

## Example:

gnormal(100, 0.01, 2.0, 3.0, 1)

creates a 100 point, normally distributed random series of values from a population where the mean is 2.0 and the standard deviation is 3.0. The result has a mean of approximately 2.0 and a standard deviation of approximately 3.0.

## Example:

gnormal(100, 0.01)

creates a 100 point, normally distributed random series with a mean of 0.0 and standard deviation of 1.0.

## Example:

W1: gnormal(5000, 1, -1, 3);label("Random Gaussian")

W2: hist(w1, 50, "pdf");label("Histogram")

W3: pdfnorm(xvals(W2), -1, 3);lines;overp(W2, lred);label("Pdfnorm") W1 contains 50000 samples of normally distributed random values with a mean of -1 and a standard deviation of 3.

W2 contains a 50 sample normalized histogram of W1.

W3 compares the distribution of the generated normally distributed random series to the analytic distribution with a mean of -1 and a standard deviation of 3.

## Remarks:

GNORMAL uses the polar modification of the Box-Muller method to transform uniformly distributed random values to normally distributed random values. The resulting values are effectively chosen from a normally distributed random population with the specified mean and standard deviation.

If unscale is 0, the result is scaled to have precisely the specified mean and standard deviation. If unscale is 1, the values are not scaled and the resulting series will have approximately the specified mean and standard deviation.

The default unscale mode can be set with the RANDN_MODE configuration parameter.

The probability density function, f(x), for normally distributed random values is: where μ is the mean, σ is the standard deviation and σ2 is the variance. The cumulative distribution function, Φ(x), is: where erf(x) is the error function implemented by ERF.

See PDFNORM to compute the probability density function and PROBN to compute the cumulative distribution function.

Approximately 68% of the values from a normal distribution are within one standard deviation away from the mean. Approximately 95% of the values lie within two standard deviations and approximately 99.7% are within three standard deviations. This is known as the 3-sigma rule.

See SEEDRAND to set a new seed value for the pseudo-random sequence.

GNORMAL can be abbreviated GNORM.

ERF

GRANDBINOMIAL

GRANDGAMMA

GRANDOM

GRANDPOISSON

HISTOGRAM

PDFNORM

PROBN

RAND

RANDN

SEEDRAND