randomNormal

../../_images/OpenMp_27.png

Generates pseudorandom numbers from a normal, \(N(\mu,\sigma^2)\), distribution.

Synopsis

randomNormal (nRandom)

Required Arguments

int nRandom (Input)
Number of random numbers to generate.

Return Value

An array of length nRandom containing the random normal deviates.

Optional Arguments

mean, float (Input)

Parameter mean contains the mean, μ, of the \(N(\mu,\sigma^2)\) from which random normal deviates are to be generated.

Default: mean = 0.0

variance, float (Input)

Parameter variance contains the variance of the \(N(\mu,\sigma^2)\) from which random normal deviates are to be generated.

Default: variance = 1.0

zigguratMethod, (Input)
By default, random numbers are generated using an inverse CDF technique. When optional argument zigguratMethod is specified, the Ziggurat method is used instead. See the “Description” section for details about each method.

Description

By default, function randomNormal generates pseudorandom numbers from a normal (Gaussian) distribution using an inverse CDF technique. In this method, a uniform (0, 1) random deviate is generated. The inverse of the normal distribution function is then evaluated at that point, using the function normalInverseCdf (Chapter 11, Probability Distribution Functions and Inverses).

If optional argument zigguratMethod is specified, function randomNormal generates pseudorandom numbers using the Ziggurat method. This method cuts the density into many small pieces. For each random number generated, an interval is chosen at random and a random normal is generated from the chosen interval. In this implementation, the density is cut into 256 pieces, but symmetry is used so that only 128 pieces are needed by the computation. Following Doornik (2005), different uniform random deviates are used to determine which slice to use and to determine the normal deviate from the slice. This method is faster than the default inverse CDF technique.

Remarks

Function randomSeedSet can be used to initialize the seed of the random number generator; function randomOption can be used to select the form of the generator.

Example

In this example, randomNormal generates five pseudorandom deviates from a standard normal distribution.

from __future__ import print_function
from numpy import *
from pyimsl.stat.randomNormal import randomNormal
from pyimsl.stat.randomSeedSet import randomSeedSet

n_random = 5
randomSeedSet(123457)
r = randomNormal(n_random)
print("Standard normal random deviates:\n%8.4f%8.4f%8.4f%8.4f%8.4f"
      % (r[0], r[1], r[2], r[3], r[4]))

Output

Standard normal random deviates:
  1.8279 -0.6412  0.7266  0.1747  1.0145