@@ -106,6 +106,19 @@ def _verify(name, computed, expected):
106106# Adrian Baddeley.
107107
108108class Random :
109+ """Random number generator base class used by bound module functions.
110+
111+ Used to instantiate instances of Random to get generators that don't
112+ share state. Especially useful for multi-threaded programs, creating
113+ a different instance of Random for each thread, and using the jumpahead()
114+ method to ensure that the generated sequences seen by each thread don't
115+ overlap.
116+
117+ Class Random can also be subclassed if you want to use a different basic
118+ generator of your own devising: in that case, override the following
119+ methods: random(), seed(), getstate(), setstate() and jumpahead().
120+
121+ """
109122
110123 VERSION = 1 # used by getstate/setstate
111124
@@ -358,6 +371,11 @@ def uniform(self, a, b):
358371## -------------------- normal distribution --------------------
359372
360373 def normalvariate (self , mu , sigma ):
374+ """Normal distribution.
375+
376+ mu is the mean, and sigma is the standard deviation.
377+
378+ """
361379 # mu = mean, sigma = standard deviation
362380
363381 # Uses Kinderman and Monahan method. Reference: Kinderman,
@@ -378,19 +396,48 @@ def normalvariate(self, mu, sigma):
378396## -------------------- lognormal distribution --------------------
379397
380398 def lognormvariate (self , mu , sigma ):
399+ """Log normal distribution.
400+
401+ If you take the natural logarithm of this distribution, you'll get a
402+ normal distribution with mean mu and standard deviation sigma.
403+ mu can have any value, and sigma must be greater than zero.
404+
405+ """
381406 return _exp (self .normalvariate (mu , sigma ))
382407
383408## -------------------- circular uniform --------------------
384409
385410 def cunifvariate (self , mean , arc ):
411+ """Circular uniform distribution.
412+
413+ mean is the mean angle, and arc is the range of the distribution,
414+ centered around the mean angle. Both values must be expressed in
415+ radians. Returned values range between mean - arc/2 and
416+ mean + arc/2 and are normalized to between 0 and pi.
417+
418+ Deprecated in version 2.3. Use:
419+ (mean + arc * (Random.random() - 0.5)) % Math.pi
420+
421+ """
386422 # mean: mean angle (in radians between 0 and pi)
387423 # arc: range of distribution (in radians between 0 and pi)
424+ import warnings
425+ warnings .warn ("The cunifvariate function is deprecated; Use (mean "
426+ "+ arc * (Random.random() - 0.5)) % Math.pi instead" ,
427+ DeprecationWarning )
388428
389429 return (mean + arc * (self .random () - 0.5 )) % _pi
390430
391431## -------------------- exponential distribution --------------------
392432
393433 def expovariate (self , lambd ):
434+ """Exponential distribution.
435+
436+ lambd is 1.0 divided by the desired mean. (The parameter would be
437+ called "lambda", but that is a reserved word in Python.) Returned
438+ values range from 0 to positive infinity.
439+
440+ """
394441 # lambd: rate lambd = 1/mean
395442 # ('lambda' is a Python reserved word)
396443
@@ -403,6 +450,14 @@ def expovariate(self, lambd):
403450## -------------------- von Mises distribution --------------------
404451
405452 def vonmisesvariate (self , mu , kappa ):
453+ """Circular data distribution.
454+
455+ mu is the mean angle, expressed in radians between 0 and 2*pi, and
456+ kappa is the concentration parameter, which must be greater than or
457+ equal to zero. If kappa is equal to zero, this distribution reduces
458+ to a uniform random angle over the range 0 to 2*pi.
459+
460+ """
406461 # mu: mean angle (in radians between 0 and 2*pi)
407462 # kappa: concentration parameter kappa (>= 0)
408463 # if kappa = 0 generate uniform random angle
@@ -445,6 +500,11 @@ def vonmisesvariate(self, mu, kappa):
445500## -------------------- gamma distribution --------------------
446501
447502 def gammavariate (self , alpha , beta ):
503+ """Gamma distribution. Not the gamma function!
504+
505+ Conditions on the parameters are alpha > 0 and beta > 0.
506+
507+ """
448508
449509 # alpha > 0, beta > 0, mean is alpha*beta, variance is alpha*beta**2
450510
@@ -524,6 +584,14 @@ def stdgamma(self, alpha, ainv, bbb, ccc):
524584## -------------------- Gauss (faster alternative) --------------------
525585
526586 def gauss (self , mu , sigma ):
587+ """Gaussian distribution.
588+
589+ mu is the mean, and sigma is the standard deviation. This is
590+ slightly faster than the normalvariate() function.
591+
592+ Not thread-safe without a lock around calls.
593+
594+ """
527595
528596 # When x and y are two variables from [0, 1), uniformly
529597 # distributed, then
@@ -569,6 +637,13 @@ def gauss(self, mu, sigma):
569637## was dead wrong, and how it probably got that way.
570638
571639 def betavariate (self , alpha , beta ):
640+ """Beta distribution.
641+
642+ Conditions on the parameters are alpha > -1 and beta} > -1.
643+ Returned values range between 0 and 1.
644+
645+ """
646+
572647 # This version due to Janne Sinkkonen, and matches all the std
573648 # texts (e.g., Knuth Vol 2 Ed 3 pg 134 "the beta distribution").
574649 y = self .gammavariate (alpha , 1. )
@@ -580,6 +655,7 @@ def betavariate(self, alpha, beta):
580655## -------------------- Pareto --------------------
581656
582657 def paretovariate (self , alpha ):
658+ """Pareto distribution. alpha is the shape parameter."""
583659 # Jain, pg. 495
584660
585661 u = self .random ()
@@ -588,6 +664,11 @@ def paretovariate(self, alpha):
588664## -------------------- Weibull --------------------
589665
590666 def weibullvariate (self , alpha , beta ):
667+ """Weibull distribution.
668+
669+ alpha is the scale parameter and beta is the shape parameter.
670+
671+ """
591672 # Jain, pg. 499; bug fix courtesy Bill Arms
592673
593674 u = self .random ()
0 commit comments