File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2626
2727def randbelow (exclusive_upper_bound ):
2828 """Return a random int in the range [0, n)."""
29+ if exclusive_upper_bound <= 0 :
30+ raise ValueError ("Upper bound must be positive." )
2931 return _sysrand ._randbelow (exclusive_upper_bound )
3032
3133DEFAULT_ENTROPY = 32 # number of bytes to return by default
Original file line number Diff line number Diff line change @@ -70,6 +70,7 @@ def test_randbelow(self):
7070 for i in range (2 , 10 ):
7171 self .assertIn (secrets .randbelow (i ), range (i ))
7272 self .assertRaises (ValueError , secrets .randbelow , 0 )
73+ self .assertRaises (ValueError , secrets .randbelow , - 1 )
7374
7475
7576class Token_Tests (unittest .TestCase ):
Original file line number Diff line number Diff line change @@ -369,6 +369,7 @@ Daniel Dittmar
369369Josip Djolonga
370370Walter Dörwald
371371Jaromir Dolecek
372+ Brendan Donegan
372373Ismail Donmez
373374Robert Donohue
374375Marcos Donolo
Original file line number Diff line number Diff line change @@ -43,6 +43,9 @@ Library
4343- Issue #29085: Allow random.Random.seed() to use high quality OS randomness
4444 rather than the pid and time.
4545
46+ - Issue #29061: Fixed bug in secrets.randbelow() which would hang when given
47+ a negative input. Patch by Brendan Donegan.
48+
4649- Issue #29079: Prevent infinite loop in pathlib.resolve() on Windows
4750
4851- Issue #13051: Fixed recursion errors in large or resized
You can’t perform that action at this time.
0 commit comments