blob: b8d5f78137df383012c8b005e3e201724bff0837 [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
12equivalent to those in the \code{whrandom} module: \code{choice},
13\code{randint}, \code{random}, \code{uniform}. See the documentation
14for the \code{whrandom} module for these functions.
15
16The following functions specific to the \code{random} module are also
17defined, and all return real values. Function parameters are named
18after the corresponding variables in the distribution's equation, as
19used in common mathematical practice; most of these equations can be
20found in any statistics text.
21
22\renewcommand{\indexsubitem}{(in module random)}
23\begin{funcdesc}{betavariate}{alpha\, beta}
24Beta distribution. Conditions on the parameters are \code{alpha>-1}
25and \code{beta>-1}.
26Returned values will range between 0 and 1.
27\end{funcdesc}
28
29\begin{funcdesc}{cunifvariate}{mean\, arc}
30Circular uniform distribution. \var{mean} is the mean angle, and
31\var{arc} is the range of the distribution, centered around the mean
32angle. Both values must be expressed in radians, and can range
33between 0 and \code{pi}. Returned values will range between
34\code{mean - arc/2} and \code{mean + arc/2}.
35\end{funcdesc}
36
37\begin{funcdesc}{expovariate}{lambd}
38Exponential distribution. \var{lambd} is 1.0 divided by the desired mean.
39(The parameter would be called ``lambda'', but that's also a reserved
40word in Python.) Returned values will range from 0 to positive infinity.
41\end{funcdesc}
42
43\begin{funcdesc}{gamma}{alpha\, beta}
44Gamma distribution. (\emph{Not} the gamma function!)
45Conditions on the parameters are \code{alpha>-1} and \code{beta>0}.
46\end{funcdesc}
47
48\begin{funcdesc}{gauss}{mu\, sigma}
49Gaussian distribution. \var{mu} is the mean, and \var{sigma} is the
50standard deviation. This is slightly faster than the
51\code{normalvariate} function defined below.
52\end{funcdesc}
53
54\begin{funcdesc}{lognormvariate}{mu\, sigma}
55Log normal distribution. If you take the natural logarithm of this
56distribution, you'll get a normal distribution with mean \var{mu} and
57standard deviation \var{sigma} \var{mu} can have any value, and \var{sigma}
58must be greater than zero.
59\end{funcdesc}
60
61\begin{funcdesc}{normalvariate}{mu\, sigma}
62Normal distribution. \var{mu} is the mean, and \var{sigma} is the
63standard deviation.
64\end{funcdesc}
65
66\begin{funcdesc}{vonmisesvariate}{mu\, kappa}
67\var{mu} is the mean angle, expressed in radians between 0 and pi,
68and \var{kappa} is the concentration parameter, which must be greater
69then or equal to zero. If \var{kappa} is equal to zero, this
70distribution reduces to a uniform random angle over the range 0 to
71\code{2*pi}.
72\end{funcdesc}
Guido van Rossume47da0a1997-07-17 16:34:52 +000073
74
75\begin{seealso}
76\seemodule{whrandom}{the standard Python random number generator}
77\end{seealso}