blob: 66fda8d2993bbbbca963b952a83e4593d91d0ba6 [file] [log] [blame]
Guido van Rossum571391b1997-04-03 22:41:49 +00001\section{Standard Module \sectcode{random}}
Guido van Rossume47da0a1997-07-17 16:34:52 +00002\label{module-random}
Guido van Rossum571391b1997-04-03 22:41:49 +00003\stmodindex{random}
4
5This module implements pseudo-random number generators for various
6distributions: on the real line, there are functions to compute normal
7or Gaussian, lognormal, negative exponential, gamma, and beta
8distributions. For generating distribution of angles, the circular
9uniform and von Mises distributions are available.
10
11The module exports the following functions, which are exactly
Fred Drake2eda4ca1998-03-08 08:13:53 +000012equivalent to those in the \module{whrandom} module:
13\function{choice()}, \function{randint()}, \function{random()} and
14\function{uniform()}. See the documentation for the \module{whrandom}
15module for these functions.
Guido van Rossum571391b1997-04-03 22:41:49 +000016
Fred Drake2eda4ca1998-03-08 08:13:53 +000017The following functions specific to the \module{random} module are also
Guido van Rossum571391b1997-04-03 22:41:49 +000018defined, and all return real values. Function parameters are named
19after the corresponding variables in the distribution's equation, as
20used in common mathematical practice; most of these equations can be
21found in any statistics text.
22
Fred Drake19479911998-02-13 06:58:54 +000023\setindexsubitem{(in module random)}
Fred Drake2eda4ca1998-03-08 08:13:53 +000024\begin{funcdesc}{betavariate}{alpha, beta}
25Beta distribution. Conditions on the parameters are
26\code{\var{alpha}>-1} and \code{\var{beta}>-1}.
Guido van Rossum571391b1997-04-03 22:41:49 +000027Returned values will range between 0 and 1.
28\end{funcdesc}
29
Fred Drake2eda4ca1998-03-08 08:13:53 +000030\begin{funcdesc}{cunifvariate}{mean, arc}
Guido van Rossum571391b1997-04-03 22:41:49 +000031Circular uniform distribution. \var{mean} is the mean angle, and
32\var{arc} is the range of the distribution, centered around the mean
33angle. Both values must be expressed in radians, and can range
34between 0 and \code{pi}. Returned values will range between
Fred Drake2eda4ca1998-03-08 08:13:53 +000035\code{\var{mean} - \var{arc}/2} and \code{\var{mean} + \var{arc}/2}.
Guido van Rossum571391b1997-04-03 22:41:49 +000036\end{funcdesc}
37
38\begin{funcdesc}{expovariate}{lambd}
Fred Drake2eda4ca1998-03-08 08:13:53 +000039Exponential distribution. \var{lambd} is 1.0 divided by the desired
40mean. (The parameter would be called ``lambda'', but that is a
41reserved word in Python.) Returned values will range from 0 to
42positive infinity.
Guido van Rossum571391b1997-04-03 22:41:49 +000043\end{funcdesc}
44
Fred Drake2eda4ca1998-03-08 08:13:53 +000045\begin{funcdesc}{gamma}{alpha, beta}
46Gamma distribution. (\emph{Not} the gamma function!) Conditions on
47the parameters are \code{\var{alpha}>-1} and \code{\var{beta}>0}.
Guido van Rossum571391b1997-04-03 22:41:49 +000048\end{funcdesc}
49
Fred Drake2eda4ca1998-03-08 08:13:53 +000050\begin{funcdesc}{gauss}{mu, sigma}
Guido van Rossum571391b1997-04-03 22:41:49 +000051Gaussian distribution. \var{mu} is the mean, and \var{sigma} is the
52standard deviation. This is slightly faster than the
Fred Drake2eda4ca1998-03-08 08:13:53 +000053\function{normalvariate()} function defined below.
Guido van Rossum571391b1997-04-03 22:41:49 +000054\end{funcdesc}
55
Fred Drake2eda4ca1998-03-08 08:13:53 +000056\begin{funcdesc}{lognormvariate}{mu, sigma}
Guido van Rossum571391b1997-04-03 22:41:49 +000057Log normal distribution. If you take the natural logarithm of this
58distribution, you'll get a normal distribution with mean \var{mu} and
Fred Drake2eda4ca1998-03-08 08:13:53 +000059standard deviation \var{sigma}. \var{mu} can have any value, and \var{sigma}
Guido van Rossum571391b1997-04-03 22:41:49 +000060must be greater than zero.
61\end{funcdesc}
62
Fred Drake2eda4ca1998-03-08 08:13:53 +000063\begin{funcdesc}{normalvariate}{mu, sigma}
Guido van Rossum571391b1997-04-03 22:41:49 +000064Normal distribution. \var{mu} is the mean, and \var{sigma} is the
65standard deviation.
66\end{funcdesc}
67
Fred Drake2eda4ca1998-03-08 08:13:53 +000068\begin{funcdesc}{vonmisesvariate}{mu, kappa}
Guido van Rossum571391b1997-04-03 22:41:49 +000069\var{mu} is the mean angle, expressed in radians between 0 and pi,
70and \var{kappa} is the concentration parameter, which must be greater
71then or equal to zero. If \var{kappa} is equal to zero, this
72distribution reduces to a uniform random angle over the range 0 to
Fred Drake2eda4ca1998-03-08 08:13:53 +000073$2\pi$.
Guido van Rossum571391b1997-04-03 22:41:49 +000074\end{funcdesc}
Guido van Rossume47da0a1997-07-17 16:34:52 +000075
Guido van Rossum4f80b651997-12-30 17:38:05 +000076\begin{funcdesc}{paretovariate}{alpha}
77Pareto distribution. \var{alpha} is the shape parameter.
78\end{funcdesc}
79
80\begin{funcdesc}{weibullvariate}{alpha, beta}
Fred Drake2eda4ca1998-03-08 08:13:53 +000081Weibull distribution. \var{alpha} is the scale parameter and
Guido van Rossum4f80b651997-12-30 17:38:05 +000082\var{beta} is the shape parameter.
83\end{funcdesc}
Guido van Rossume47da0a1997-07-17 16:34:52 +000084
85\begin{seealso}
86\seemodule{whrandom}{the standard Python random number generator}
87\end{seealso}