MCPcopy Index your code
hub / github.com/python/cpython / normalvariate

Method normalvariate

Lib/random.py:536–555  ·  view source on GitHub ↗

Normal distribution. mu is the mean, and sigma is the standard deviation.

(self, mu=0.0, sigma=1.0)

Source from the content-addressed store, hash-verified

534 return low + (high - low) * _sqrt(u * c)
535
536 def normalvariate(self, mu=0.0, sigma=1.0):
537 """Normal distribution.
538
539 mu is the mean, and sigma is the standard deviation.
540
541 """
542 # Uses Kinderman and Monahan method. Reference: Kinderman,
543 # A.J. and Monahan, J.F., "Computer generation of random
544 # variables using the ratio of uniform deviates", ACM Trans
545 # Math Software, 3, (1977), pp257-260.
546
547 random = self.random
548 while True:
549 u1 = random()
550 u2 = 1.0 - random()
551 z = NV_MAGICCONST * (u1 - 0.5) / u2
552 zz = z * z / 4.0
553 if zz <= -_log(u2):
554 break
555 return mu + z * sigma
556
557 def gauss(self, mu=0.0, sigma=1.0):
558 """Gaussian distribution.

Callers 3

lognormvariateMethod · 0.95
test_zeroinputsMethod · 0.95

Calls

no outgoing calls

Tested by 2

test_zeroinputsMethod · 0.76