Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def _randbelow_with_getrandbits(self, n):
"Return a random int in the range [0,n). Defined for n > 0."

getrandbits = self.getrandbits
k = n.bit_length()
k = (n - 1).bit_length()
r = getrandbits(k) # 0 <= r < 2**k
while r >= n:
r = getrandbits(k)
Expand Down
30 changes: 15 additions & 15 deletions Lib/test/test_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1164,22 +1164,22 @@ def b():
A->F B->B C->C D->D E->F F->F G->G H->H I->I J->J K->B L->L M->M
merged D into C
A->F B->B C->C D->C E->F F->F G->G H->H I->I J->J K->B L->L M->M
merged M into C
A->F B->B C->C D->C E->F F->F G->G H->H I->I J->J K->B L->L M->C
merged J into B
A->F B->B C->C D->C E->F F->F G->G H->H I->I J->B K->B L->L M->C
merged M into B
A->F B->B C->C D->C E->F F->F G->G H->H I->I J->J K->B L->L M->B
merged H into G
A->F B->B C->C D->C E->F F->F G->G H->G I->I J->J K->B L->L M->B
merged B into C
A->F B->C C->C D->C E->F F->F G->G H->H I->I J->C K->C L->L M->C
merged F into G
A->G B->C C->C D->C E->G F->G G->G H->H I->I J->C K->C L->L M->C
merged L into C
A->G B->C C->C D->C E->G F->G G->G H->H I->I J->C K->C L->C M->C
merged G into I
A->I B->C C->C D->C E->I F->I G->I H->H I->I J->C K->C L->C M->C
merged I into H
A->H B->C C->C D->C E->H F->H G->H H->H I->H J->C K->C L->C M->C
merged C into H
A->H B->H C->H D->H E->H F->H G->H H->H I->H J->H K->H L->H M->H
A->F B->C C->C D->C E->F F->F G->G H->G I->I J->J K->C L->L M->C
merged C into G
A->F B->G C->G D->G E->F F->F G->G H->G I->I J->J K->G L->L M->G
merged G into J
A->F B->J C->J D->J E->F F->F G->J H->J I->I J->J K->J L->L M->J
merged J into F
A->F B->F C->F D->F E->F F->F G->F H->F I->I J->F K->F L->L M->F
merged L into F
A->F B->F C->F D->F E->F F->F G->F H->F I->I J->F K->F L->F M->F
merged I into F
A->F B->F C->F D->F E->F F->F G->F H->F I->F J->F K->F L->F M->F

"""
# Emacs turd '
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ def test_randrange_uses_getrandbits(self):
self.gen.seed(1234567)
# If randrange uses getrandbits, it should pick getrandbits(100)
# when called with a 100-bits stop argument.
self.assertEqual(self.gen.randrange(2**99),
self.assertEqual(self.gen.randrange(2**99 + 1),
97904845777343510404718956115)

def test_randbelow_logic(self, _log=log, int=int):
Expand Down