Getting Started Documentation Glish Learn More Programming Contact Us
Version 1.9 Build 1556
News FAQ
Search Home


next up previous contents index
Next: randomnumbers - Constructor Up: mathematics - Module Previous: interpolate1dtest - Function


randomnumbers - Tool



Package utility
Module mathematics


Postscript file available

Random numbers from various statistical distributions

include "randomnumbers.g"

Constructors
randomnumbers Construct an randomnumbers tool
Functions
binomial Generate binomially distributed random numbers
discreteuniform Generate uniformly distributed random integers
done Delete the randomnumbers tool
erlang Generate random numbers that have an Erlang distribution.
geometric Generate geometrically distributed random numbers
hypergeometric Generate random numbers that have an hyper-geometric distribution.
lognormal Generate random numbers with a log-normal distribution
negativeexponential Generate random numbers with a negative-exponential distribution
normal Generate normally distributed random numbers
poisson Generate Poisson distributed random numbers
reseed Set the seed used by the random number generator.
type Return the type of this tool
uniform Generate uniformly distributed random numbers
weibull Generate random numbers with a Weibull distribution



Description

The randomnumbers tool will generate pseudo-random numbers from a number of common distribution functions.

This tool will generate random numbers from the following distributions:

normal
This is a continious distribution that is also known as the Gaussian distribution. The probability density function is given by:

p(x) = $\displaystyle {\frac{1}{\sigma\sqrt{2\pi}}}$exp$\displaystyle \left(\vphantom{\frac{-1}{2}\left(\frac{x-m}{\sigma}\right)^2}\right.$$\displaystyle {\frac{-1}{2}}$$\displaystyle \left(\vphantom{\frac{x-m}{\sigma}}\right.$$\displaystyle {\frac{x-m}{\sigma}}$ $\displaystyle \left.\vphantom{\frac{x-m}{\sigma}}\right)^{2}_{}$ $\displaystyle \left.\vphantom{\frac{-1}{2}\left(\frac{x-m}{\sigma}\right)^2}\right)$ (1.14)

where m is the mean and $ \sigma^{2}_{}$ is the variance.

uniform
This is a continuous distribution where every number between the specified upper and lower bounds is equally probable. The returned values include the lower bound but not the upper bound. The probability density function is given by:

p(x) = $\displaystyle {\frac{1}{u-l}}$ (1.15)

where u is the upper and l is the lower bound.

discrete uniform
This is a discrete distribution where all the integral values between the specified upper and lower bounds are equally probable. The returned values include the lower & upper bounds. The point probabilities are given by:

p(x) = $\displaystyle {\frac{1}{u-l}}$ (1.16)

where u is the upper and l is the lower bound and x is an integral value in the range [l, u].

binomial
This is a discrete distribution where integers between zero and a specified number of throws n may be returned. The point probabilities are given by:

p(x) = $\displaystyle \left(\vphantom{\begin{array}{c}n\\  x\end{array}}\right.$$\displaystyle \begin{array}{c}n\\  x\end{array}$ $\displaystyle \left.\vphantom{\begin{array}{c}n\\  x\end{array}}\right)$px$\displaystyle \left(\vphantom{1-p}\right.$1 - p$\displaystyle \left.\vphantom{1-p}\right)^{n-x}_{}$ (1.17)

where n is the number of throws, p is the probability of of an individual throw and x is an integer in the range [0, n].

poisson
This is a discrete distribution where non-negative integers may be returned. The point probabilities are given by:

p(x) = $\displaystyle {\frac{e^{-m}m^x}{x!}}$ (1.18)

where m is the mean of of the distribution and x is an integer in the range [0,$ \infty$).

geometric
This is a discrete distribution where non-negative integers may be returned. The point probabilities are given by:

p(x) = p$\displaystyle \left(\vphantom{1-p}\right.$1 - p$\displaystyle \left.\vphantom{1-p}\right)^{x}_{}$ (1.19)

where p is a probability and x is an integer in the range [0,$ \infty$).
hypergeometric
This is a continuous distribution.

erlang
This is a continuous distribution that is more commonly known as the Gamma distribution. The probability density function is given by:

p(x) = $\displaystyle {\frac{1}{\Gamma\left(\alpha+1\right)\beta^{\alpha+1}}}$x$\scriptstyle \alpha$e-x/$\scriptstyle \beta$ (1.20)

where the mean is given by $ \beta$($ \alpha$ + 1) and the variance is given by $ \beta^{2}_{}$($ \alpha$ + 1). $ \Gamma$(x) is the gamma function.

lognormal
This is a continuous distribution.

negative exponential
This is a continuous distribution that is also known as the exponential distribution. The probability density function is given by:

p(x) = $\displaystyle {\frac{1}{m}}$exp$\displaystyle \left(\vphantom{\frac{-x}{m}}\right.$$\displaystyle {\frac{-x}{m}}$ $\displaystyle \left.\vphantom{\frac{-x}{m}}\right)$ (1.21)

where m is the mean. p(x) is zero when x is negative. This distribution is sometimes known as the exponential distribution.
weibull
This is a continuous distribution.

The builtin function random() of glish can be used to generate a sequence of uniformly distributed random numbers. These are random integers between optionally specified bounds. This is a discrete uniform distribution and hence is similar in functionality to the discreteuniform function in this tool.



See Also
Handbook of Mathematical Functions, Abramowitz and Stegun

The C++ class, Random.

The Glish built-in function, random.



Example
To use the functions in this tool we have to firstly, as shown in line 1, load the definition of the randomnumbers tool and then, as shown in line 2, construct a randomnumbers tool that will actually perform the computations.

    include 'randomnumbers.g' #1
    rand := randomnumbers();  #2

The rand tool is now ready for use. To generate a sequence of 100 random numbers which are normally distributed with a mean of 0.5 and variance of 1.0 the normal function is used. ie.,

    x := rand.normal(0.5, 1.0, 100);

A 10 by 20 two-dimensional array of Poisson distributed random numbers, with a mean of 6.5, can be generated using,

    x := rand.poisson(6.5, [10,20]);

The glish variable x would now have a shape of [10,20], where each element of which will be a random number from a poisson distribution.

The random number generator will always produce the same sequence of numbers for a given set of seeds. To generate a new sequence of random numbers, one has to reset the random number generator by supplying a new seed. This can be done using:

    rand.reseed(12.34);
where seed can be any number. If called with the unset value, which is the default, this function will use the glish random function to supply a seed.

Once you are finished with this tool you should call the done function to release all the memory used by this tool. If no other tools are using the server then this will also be shut down.

    rand.done();




next up previous contents index
Next: randomnumbers - Constructor Up: mathematics - Module Previous: interpolate1dtest - Function   Contents   Index
Please send questions or comments about AIPS++ to aips2-request@nrao.edu.
Copyright © 1995-2000 Associated Universities Inc., Washington, D.C.

Return to AIPS++ Home Page
2006-10-15