diff options
author | Victor Stinner <vstinner@python.org> | 2020-04-29 16:49:00 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-29 16:49:00 (GMT) |
commit | 2d8757758d0d75882fef0fe0e3c74c4756b3e81e (patch) | |
tree | 676e735cf1076bf60f2a7412e67e394e6b0f7948 /Lib/random.py | |
parent | e3dfb9b967c560f4d094092dcae4a16fc9634681 (diff) | |
download | cpython-2d8757758d0d75882fef0fe0e3c74c4756b3e81e.zip cpython-2d8757758d0d75882fef0fe0e3c74c4756b3e81e.tar.gz cpython-2d8757758d0d75882fef0fe0e3c74c4756b3e81e.tar.bz2 |
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().
Diffstat (limited to 'Lib/random.py')
-rw-r--r-- | Lib/random.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/random.py b/Lib/random.py index f1df18d..80fe447 100644 --- a/Lib/random.py +++ b/Lib/random.py @@ -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 |