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
b4d0a0e3
Commit
b4d0a0e3
authored
Oct 05, 2013
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Plain Diff
merge
parents
328e17c9
3beba795
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
2 deletions
+4
-2
Lib/random.py
Lib/random.py
+2
-2
Lib/test/test_collections.py
Lib/test/test_collections.py
+2
-0
No files found.
Lib/random.py
View file @
b4d0a0e3
...
...
@@ -220,10 +220,11 @@ class Random(_random.Random):
Method
=
_MethodType
,
BuiltinMethod
=
_BuiltinMethodType
):
"Return a random int in the range [0,n). Raises ValueError if n==0."
random
=
self
.
random
getrandbits
=
self
.
getrandbits
# Only call self.getrandbits if the original random() builtin method
# has not been overridden or if a new getrandbits() was supplied.
if
type
(
self
.
random
)
is
BuiltinMethod
or
type
(
getrandbits
)
is
Method
:
if
type
(
random
)
is
BuiltinMethod
or
type
(
getrandbits
)
is
Method
:
k
=
n
.
bit_length
()
# don't use (n-1) here because n can be 1
r
=
getrandbits
(
k
)
# 0 <= r < 2**k
while
r
>=
n
:
...
...
@@ -231,7 +232,6 @@ class Random(_random.Random):
return
r
# There's an overriden random() method but no new getrandbits() method,
# so we can only use random() from here.
random
=
self
.
random
if
n
>=
maxsize
:
_warn
(
"Underlying random() generator does not supply
\
n
"
"enough bits to choose from a population range this large.
\
n
"
...
...
Lib/test/test_collections.py
View file @
b4d0a0e3
...
...
@@ -1080,8 +1080,10 @@ class TestCounter(unittest.TestCase):
# test fidelity to the pure python version
c
=
CounterSubclassWithSetItem
(
'abracadabra'
)
self
.
assertTrue
(
c
.
called
)
self
.
assertEqual
(
dict
(
c
),
{
'a'
:
5
,
'b'
:
2
,
'c'
:
1
,
'd'
:
1
,
'r'
:
2
})
c
=
CounterSubclassWithGet
(
'abracadabra'
)
self
.
assertTrue
(
c
.
called
)
self
.
assertEqual
(
dict
(
c
),
{
'a'
:
5
,
'b'
:
2
,
'c'
:
1
,
'd'
:
1
,
'r'
:
2
})
################################################################################
...
...
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