bpo-40286: Remove C implementation of Random.randbytes() (GH-19797)

Remove _random.Random.randbytes(): the C implementation of
randbytes(). Implement the method in Python to ease subclassing:
randbytes() now directly reuses getrandbits().
This commit is contained in:
Victor Stinner 2020-04-29 18:49:00 +02:00 committed by GitHub
parent e3dfb9b967
commit 2d8757758d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 87 deletions

View file

@ -192,6 +192,12 @@ class Random(_random.Random):
## ---- Methods below this point do not need to be overridden when
## ---- subclassing for the purpose of using a different core generator.
## -------------------- bytes methods ---------------------
def randbytes(self, n):
"""Generate n random bytes."""
return self.getrandbits(n * 8).to_bytes(n, 'little')
## -------------------- pickle support -------------------
# Issue 17489: Since __reduce__ was defined to fix #759889 this is no