mirror of
https://github.com/python/cpython.git
synced 2024-12-01 11:15:56 +01:00
merge
This commit is contained in:
commit
0ce64323cf
@ -26,6 +26,8 @@ choice = _sysrand.choice
|
||||
|
||||
def randbelow(exclusive_upper_bound):
|
||||
"""Return a random int in the range [0, n)."""
|
||||
if exclusive_upper_bound <= 0:
|
||||
raise ValueError("Upper bound must be positive.")
|
||||
return _sysrand._randbelow(exclusive_upper_bound)
|
||||
|
||||
DEFAULT_ENTROPY = 32 # number of bytes to return by default
|
||||
|
@ -70,6 +70,7 @@ class Random_Tests(unittest.TestCase):
|
||||
for i in range(2, 10):
|
||||
self.assertIn(secrets.randbelow(i), range(i))
|
||||
self.assertRaises(ValueError, secrets.randbelow, 0)
|
||||
self.assertRaises(ValueError, secrets.randbelow, -1)
|
||||
|
||||
|
||||
class Token_Tests(unittest.TestCase):
|
||||
|
Loading…
Reference in New Issue
Block a user