mirror of
https://github.com/python/cpython.git
synced 2025-10-09 08:31:26 +00:00
bpo-45155: Apply new byteorder default values for int.to/from_bytes (GH-28465)
This commit is contained in:
parent
5846c9b71e
commit
9510e6f3c7
5 changed files with 15 additions and 15 deletions
|
@ -154,7 +154,7 @@ class Random(_random.Random):
|
|||
elif version == 2 and isinstance(a, (str, bytes, bytearray)):
|
||||
if isinstance(a, str):
|
||||
a = a.encode()
|
||||
a = int.from_bytes(a + _sha512(a).digest(), 'big')
|
||||
a = int.from_bytes(a + _sha512(a).digest())
|
||||
|
||||
elif not isinstance(a, (type(None), int, float, str, bytes, bytearray)):
|
||||
raise TypeError('The only supported seed types are: None,\n'
|
||||
|
@ -795,14 +795,14 @@ class SystemRandom(Random):
|
|||
|
||||
def random(self):
|
||||
"""Get the next random number in the range [0.0, 1.0)."""
|
||||
return (int.from_bytes(_urandom(7), 'big') >> 3) * RECIP_BPF
|
||||
return (int.from_bytes(_urandom(7)) >> 3) * RECIP_BPF
|
||||
|
||||
def getrandbits(self, k):
|
||||
"""getrandbits(k) -> x. Generates an int with k random bits."""
|
||||
if k < 0:
|
||||
raise ValueError('number of bits must be non-negative')
|
||||
numbytes = (k + 7) // 8 # bits / 8 and rounded up
|
||||
x = int.from_bytes(_urandom(numbytes), 'big')
|
||||
x = int.from_bytes(_urandom(numbytes))
|
||||
return x >> (numbytes * 8 - k) # trim excess bits
|
||||
|
||||
def randbytes(self, n):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue