Remove unnecessary and over-restrictive type check (GH-10905)
This commit is contained in:
parent
b8e689a6e8
commit
09473ac063
|
@ -718,8 +718,6 @@ class SystemRandom(Random):
|
||||||
"""getrandbits(k) -> x. Generates an int with k random bits."""
|
"""getrandbits(k) -> x. Generates an int with k random bits."""
|
||||||
if k <= 0:
|
if k <= 0:
|
||||||
raise ValueError('number of bits must be greater than zero')
|
raise ValueError('number of bits must be greater than zero')
|
||||||
if k != int(k):
|
|
||||||
raise TypeError('number of bits should be an integer')
|
|
||||||
numbytes = (k + 7) // 8 # bits / 8 and rounded up
|
numbytes = (k + 7) // 8 # bits / 8 and rounded up
|
||||||
x = int.from_bytes(_urandom(numbytes), 'big')
|
x = int.from_bytes(_urandom(numbytes), 'big')
|
||||||
return x >> (numbytes * 8 - k) # trim excess bits
|
return x >> (numbytes * 8 - k) # trim excess bits
|
||||||
|
|
Loading…
Reference in New Issue