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