The RNG package provides any number of independent random number generators tied to a distribution. Distributions include exponential, normal, and log-normal distributions, but adding others is not difficult. Contributions of code for other distributions are welcome!
RNG was written by Konrad Hinsen based on the package URNG by Paul Dubois and Fred Fritsch of LLNL. This package has been released for unlimited redistribution. Please see License and disclaimer for packages MA, RNG, Properties.
Package RNG installs two modules: RNG.RNG, and RNG.ranf. The former is a C extension that does the generation. The latter is an easy-to-use interface for a single uniform distribution.
Module RNG defines the function:
CreateGenerator(s, distribution=UniformDistribution(0., 1.))
creates a new random number generator with a distribution. The random numbers produced by the generator sample the distribution and are independent of other generators created earlier or later. Its first argument, an integer, determines the initial state:
The default distribution is a uniform distribution on [0., 1.); other distributions are obtained by supplying a second argument which must be a distribution. Currently RNG defines the following distribution types:
Module ranf, whose main function ranf() is equivalent to the old ranf generator on Cray 1 computers, defines these facilities.
Attribute standard_generator is an instance of RNG.UniformDistribution(0., 1.).
ranf(): returns a random number from the standard_generator.
random_sample(*n) returns a Numeric array of samples from the standard_generator.
The test routine Demo/RNGdemo.py illustrates some common usage of both RNG and Numeric.
The test routine RNGtest2.py combines RNG with Konrad Hinsen's Statistics package to do a test of the log normal distribution.
Here is one function from RNGdemo.py, showing a test of a normal distribution.
def test_normal (mean, std, n=10000):
dist = RNG.NormalDistribution(mean, std)
rng = RNG.CreateGenerator(0, dist)