diff options
author | Andrew Svetlov <andrew.svetlov@gmail.com> | 2013-04-12 20:27:37 (GMT) |
---|---|---|
committer | Andrew Svetlov <andrew.svetlov@gmail.com> | 2013-04-12 20:27:37 (GMT) |
commit | 730001163f1bd7469c17743e1846cf2761639191 (patch) | |
tree | 2a566bd9998cc2fc632b40fb84bb47af8c721efe /Lib/random.py | |
parent | 3042b5ebf4aee83957428870b86de394646b731c (diff) | |
parent | a2dfc35a1341fc73a074cda9190bb99a821f8095 (diff) | |
download | cpython-730001163f1bd7469c17743e1846cf2761639191.zip cpython-730001163f1bd7469c17743e1846cf2761639191.tar.gz cpython-730001163f1bd7469c17743e1846cf2761639191.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 b183f56..2fa9887 100644 --- a/Lib/random.py +++ b/Lib/random.py @@ -345,6 +345,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: |