Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 1 | \section{Standard Module \sectcode{random}} |
Guido van Rossum | e47da0a | 1997-07-17 16:34:52 +0000 | [diff] [blame] | 2 | \label{module-random} |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 3 | \stmodindex{random} |
| 4 | |
| 5 | This module implements pseudo-random number generators for various |
| 6 | distributions: on the real line, there are functions to compute normal |
| 7 | or Gaussian, lognormal, negative exponential, gamma, and beta |
| 8 | distributions. For generating distribution of angles, the circular |
| 9 | uniform and von Mises distributions are available. |
| 10 | |
| 11 | The module exports the following functions, which are exactly |
| 12 | equivalent to those in the \code{whrandom} module: \code{choice}, |
| 13 | \code{randint}, \code{random}, \code{uniform}. See the documentation |
| 14 | for the \code{whrandom} module for these functions. |
| 15 | |
| 16 | The following functions specific to the \code{random} module are also |
| 17 | defined, and all return real values. Function parameters are named |
| 18 | after the corresponding variables in the distribution's equation, as |
| 19 | used in common mathematical practice; most of these equations can be |
| 20 | found in any statistics text. |
| 21 | |
Fred Drake | 1947991 | 1998-02-13 06:58:54 +0000 | [diff] [blame] | 22 | \setindexsubitem{(in module random)} |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 23 | \begin{funcdesc}{betavariate}{alpha\, beta} |
| 24 | Beta distribution. Conditions on the parameters are \code{alpha>-1} |
| 25 | and \code{beta>-1}. |
| 26 | Returned values will range between 0 and 1. |
| 27 | \end{funcdesc} |
| 28 | |
| 29 | \begin{funcdesc}{cunifvariate}{mean\, arc} |
| 30 | Circular uniform distribution. \var{mean} is the mean angle, and |
| 31 | \var{arc} is the range of the distribution, centered around the mean |
| 32 | angle. Both values must be expressed in radians, and can range |
| 33 | between 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} |
| 38 | Exponential distribution. \var{lambd} is 1.0 divided by the desired mean. |
| 39 | (The parameter would be called ``lambda'', but that's also a reserved |
| 40 | word in Python.) Returned values will range from 0 to positive infinity. |
| 41 | \end{funcdesc} |
| 42 | |
| 43 | \begin{funcdesc}{gamma}{alpha\, beta} |
| 44 | Gamma distribution. (\emph{Not} the gamma function!) |
| 45 | Conditions on the parameters are \code{alpha>-1} and \code{beta>0}. |
| 46 | \end{funcdesc} |
| 47 | |
| 48 | \begin{funcdesc}{gauss}{mu\, sigma} |
| 49 | Gaussian distribution. \var{mu} is the mean, and \var{sigma} is the |
| 50 | standard deviation. This is slightly faster than the |
| 51 | \code{normalvariate} function defined below. |
| 52 | \end{funcdesc} |
| 53 | |
| 54 | \begin{funcdesc}{lognormvariate}{mu\, sigma} |
| 55 | Log normal distribution. If you take the natural logarithm of this |
| 56 | distribution, you'll get a normal distribution with mean \var{mu} and |
| 57 | standard deviation \var{sigma} \var{mu} can have any value, and \var{sigma} |
| 58 | must be greater than zero. |
| 59 | \end{funcdesc} |
| 60 | |
| 61 | \begin{funcdesc}{normalvariate}{mu\, sigma} |
| 62 | Normal distribution. \var{mu} is the mean, and \var{sigma} is the |
| 63 | standard 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, |
| 68 | and \var{kappa} is the concentration parameter, which must be greater |
| 69 | then or equal to zero. If \var{kappa} is equal to zero, this |
| 70 | distribution reduces to a uniform random angle over the range 0 to |
| 71 | \code{2*pi}. |
| 72 | \end{funcdesc} |
Guido van Rossum | e47da0a | 1997-07-17 16:34:52 +0000 | [diff] [blame] | 73 | |
Guido van Rossum | 4f80b65 | 1997-12-30 17:38:05 +0000 | [diff] [blame] | 74 | \begin{funcdesc}{paretovariate}{alpha} |
| 75 | Pareto distribution. \var{alpha} is the shape parameter. |
| 76 | \end{funcdesc} |
| 77 | |
| 78 | \begin{funcdesc}{weibullvariate}{alpha, beta} |
| 79 | Weibull distribution. \var{alpha} is the scale parameter, and |
| 80 | \var{beta} is the shape parameter. |
| 81 | \end{funcdesc} |
Guido van Rossum | e47da0a | 1997-07-17 16:34:52 +0000 | [diff] [blame] | 82 | |
| 83 | \begin{seealso} |
| 84 | \seemodule{whrandom}{the standard Python random number generator} |
| 85 | \end{seealso} |