blob: 3bc92ce3bcfea7719df79f48c6d9f21fbac9b15d [file] [log] [blame]
Guido van Rossum571391b1997-04-03 22:41:49 +00001\section{Standard Module \sectcode{random}}
2\stmodindex{random}
3
4This module implements pseudo-random number generators for various
5distributions: on the real line, there are functions to compute normal
6or Gaussian, lognormal, negative exponential, gamma, and beta
7distributions. For generating distribution of angles, the circular
8uniform and von Mises distributions are available.
9
10The module exports the following functions, which are exactly
11equivalent to those in the \code{whrandom} module: \code{choice},
12\code{randint}, \code{random}, \code{uniform}. See the documentation
13for the \code{whrandom} module for these functions.
14
15The following functions specific to the \code{random} module are also
16defined, and all return real values. Function parameters are named
17after the corresponding variables in the distribution's equation, as
18used in common mathematical practice; most of these equations can be
19found in any statistics text.
20
21\renewcommand{\indexsubitem}{(in module random)}
22\begin{funcdesc}{betavariate}{alpha\, beta}
23Beta distribution. Conditions on the parameters are \code{alpha>-1}
24and \code{beta>-1}.
25Returned values will range between 0 and 1.
26\end{funcdesc}
27
28\begin{funcdesc}{cunifvariate}{mean\, arc}
29Circular uniform distribution. \var{mean} is the mean angle, and
30\var{arc} is the range of the distribution, centered around the mean
31angle. Both values must be expressed in radians, and can range
32between 0 and \code{pi}. Returned values will range between
33\code{mean - arc/2} and \code{mean + arc/2}.
34\end{funcdesc}
35
36\begin{funcdesc}{expovariate}{lambd}
37Exponential distribution. \var{lambd} is 1.0 divided by the desired mean.
38(The parameter would be called ``lambda'', but that's also a reserved
39word in Python.) Returned values will range from 0 to positive infinity.
40\end{funcdesc}
41
42\begin{funcdesc}{gamma}{alpha\, beta}
43Gamma distribution. (\emph{Not} the gamma function!)
44Conditions on the parameters are \code{alpha>-1} and \code{beta>0}.
45\end{funcdesc}
46
47\begin{funcdesc}{gauss}{mu\, sigma}
48Gaussian distribution. \var{mu} is the mean, and \var{sigma} is the
49standard deviation. This is slightly faster than the
50\code{normalvariate} function defined below.
51\end{funcdesc}
52
53\begin{funcdesc}{lognormvariate}{mu\, sigma}
54Log normal distribution. If you take the natural logarithm of this
55distribution, you'll get a normal distribution with mean \var{mu} and
56standard deviation \var{sigma} \var{mu} can have any value, and \var{sigma}
57must be greater than zero.
58\end{funcdesc}
59
60\begin{funcdesc}{normalvariate}{mu\, sigma}
61Normal distribution. \var{mu} is the mean, and \var{sigma} is the
62standard deviation.
63\end{funcdesc}
64
65\begin{funcdesc}{vonmisesvariate}{mu\, kappa}
66\var{mu} is the mean angle, expressed in radians between 0 and pi,
67and \var{kappa} is the concentration parameter, which must be greater
68then or equal to zero. If \var{kappa} is equal to zero, this
69distribution reduces to a uniform random angle over the range 0 to
70\code{2*pi}.
71\end{funcdesc}