mirror of
https://github.com/python/cpython.git
synced 2025-10-07 07:31:46 +00:00
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:
parent
e3dfb9b967
commit
2d8757758d
4 changed files with 10 additions and 87 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue