diff options
author | Andrew Svetlov <andrew.svetlov@gmail.com> | 2013-04-12 20:21:01 (GMT) |
---|---|---|
committer | Andrew Svetlov <andrew.svetlov@gmail.com> | 2013-04-12 20:21:01 (GMT) |
commit | a2dfc35a1341fc73a074cda9190bb99a821f8095 (patch) | |
tree | 86184e48b0199a381cebd099e2304fa635d3b621 /Lib/random.py | |
parent | 7b2c8bb833780a6f6a0b5480f65d27248d7b3b53 (diff) | |
download | cpython-a2dfc35a1341fc73a074cda9190bb99a821f8095.zip cpython-a2dfc35a1341fc73a074cda9190bb99a821f8095.tar.gz cpython-a2dfc35a1341fc73a074cda9190bb99a821f8095.tar.bz2 |
Issue #13355: Raise ValueError on random.triangular call with invalid params.
Initial patch by Yuriy Senko.
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 7d8d4f3..11a0606 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: |