Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
92df7529
Commit
92df7529
authored
May 25, 2014
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue 13355: Make random.triangular degrade gracefully when low == high.
parent
1f94efc6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
2 deletions
+8
-2
Lib/random.py
Lib/random.py
+4
-1
Lib/test/test_random.py
Lib/test/test_random.py
+1
-1
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/random.py
View file @
92df7529
...
...
@@ -371,7 +371,10 @@ class Random(_random.Random):
"""
u
=
self
.
random
()
c
=
0.5
if
mode
is
None
else
(
mode
-
low
)
/
(
high
-
low
)
try
:
c
=
0.5
if
mode
is
None
else
(
mode
-
low
)
/
(
high
-
low
)
except
ZeroDivisionError
:
return
low
if
u
>
c
:
u
=
1.0
-
u
c
=
1.0
-
c
...
...
Lib/test/test_random.py
View file @
92df7529
...
...
@@ -541,7 +541,7 @@ class TestDistributions(unittest.TestCase):
for
variate
,
args
,
expected
in
[
(
g
.
uniform
,
(
10.0
,
10.0
),
10.0
),
(
g
.
triangular
,
(
10.0
,
10.0
),
10.0
),
#
(g.triangular, (10.0, 10.0, 10.0), 10.0),
(
g
.
triangular
,
(
10.0
,
10.0
,
10.0
),
10.0
),
(
g
.
expovariate
,
(
float
(
'inf'
),),
0.0
),
(
g
.
vonmisesvariate
,
(
3.0
,
float
(
'inf'
)),
3.0
),
(
g
.
gauss
,
(
10.0
,
0.0
),
10.0
),
...
...
Misc/NEWS
View file @
92df7529
...
...
@@ -23,6 +23,9 @@ Tests
- Issue #19925: Added tests for the spwd module. Original patch by Vajrasky Kok.
- Issue #13355: random.triangular() no longer fails with a ZeroDivisionError
when low equals high.
- Issue #21522: Added Tkinter tests for Listbox.itemconfigure(),
PanedWindow.paneconfigure(), and Menu.entryconfigure().
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment