# NAME

Math::Random::NormalDistribution - Normally distributed random numbers.

# SYNOPSIS

``````    use Math::Random::NormalDistribution;

# Create generator of normally distributed numbers
# with mean 5.0 and standard deviation 3.0
my \$generator = rand_nd_generator(5.0, 3.0);

# Generate ten numbers
my @nums = map { \$generator->() } (1..10);``````

# DESCRIPTION

This module uses Box-Muller transform to generate independent, normally distributed random fractional numbers (the normal deviates), given uniformly distributed random numbers (the source is common `rand`).

# FUNCTIONS

There's only one function in this package and it's exported by default.

`rand_nd_generator(\$mean, \$stddev)`

Accepts the mean (also known as expected value, or mathematical expectation) and the standard deviation (the square root of variance). Both arguments are optional - by default, the generator returns standard numbers (with expected value 0 and standard deviation 1).

Returns a subref: reference to a function without arguments, which returns a new random number on each call.

For example, just draw a simple chart:

``````    use Math::Random::NormalDistribution;

my \$LINES = 10;
my \$VALUES = \$LINES * 15;

my @count = (0) x \$LINES;
my \$generator = rand_nd_generator(\$LINES / 2, \$LINES / 6);

for (1 .. \$VALUES) {
my \$x = \$generator->();
my \$idx = int(\$x);
next if \$idx < 0 || \$idx >= \$LINES;
\$count[\$idx]++;
}

print '|' x \$_, "\n" for (@count);``````

Output:

``````    ||
||||
|||||||||||||
||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||
||||||||||||||||||||||||||||||||
|||||||||||||||
|||||||||||||
|||||
|``````