Normal distribution. mu is the mean, and sigma is the standard deviation.
(self, mu=0.0, sigma=1.0)
| 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. |
no outgoing calls