diff options
Diffstat (limited to 'Lib/random.py')
-rw-r--r-- | Lib/random.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/random.py b/Lib/random.py index 7d8d4f3a40..11a0606e9c 100644 --- a/Lib/random.py +++ b/Lib/random.py @@ -341,6 +341,16 @@ class Random(_random.Random): http://en.wikipedia.org/wiki/Triangular_distribution """ + # Sanity check. According to the doc low must be less or equal to + # high. And mode should be somewhere between these bounds. + if low > high: + raise ValueError('high cannot be less then low.') + if mode is not None and (mode < low or mode > high): + raise ValueError('mode must be between low and high.') + + if high == low: + return low + u = self.random() c = 0.5 if mode is None else (mode - low) / (high - low) if u > c: |