Triangular distribution. Continuous distribution bounded by given lower and upper limits, and having a given mode value in-between. http://en.wikipedia.org/wiki/Triangular_distribution
(self, low=0.0, high=1.0, mode=None)
| 522 | return a + (b - a) * self.random() |
| 523 | |
| 524 | def triangular(self, low=0.0, high=1.0, mode=None): |
| 525 | """Triangular distribution. |
| 526 | |
| 527 | Continuous distribution bounded by given lower and upper limits, |
| 528 | and having a given mode value in-between. |
| 529 | |
| 530 | http://en.wikipedia.org/wiki/Triangular_distribution |
| 531 | |
| 532 | """ |
| 533 | u = self.random() |
| 534 | try: |
| 535 | c = 0.5 if mode is None else (mode - low) / (high - low) |
| 536 | except ZeroDivisionError: |
| 537 | return low |
| 538 | if u > c: |
| 539 | u = 1.0 - u |
| 540 | c = 1.0 - c |
| 541 | low, high = high, low |
| 542 | return low + (high - low) * _sqrt(u * c) |
| 543 | |
| 544 | def normalvariate(self, mu=0.0, sigma=1.0): |
| 545 | """Normal distribution. |