Campbell Barton added the comment:
@serhiy.storchaka, while a properly working function that uses getrandbits
isn't so complex, its not trivial either.
It needs to create smaller chunks and join them (also check zero size case
which raises an error if passed).
eg:
```
def urandom_from_random(rng, length):
if length == 0:
return b''
import sys
chunk_size = 65535
chunks = []
while length >= chunk_size:
chunks.append(rng.getrandbits(chunk_size * 8).to_bytes(chunk_size,
sys.byteorder))
length -= chunk_size
if length:
chunks.append(rng.getrandbits(length * 8).to_bytes(length,
sys.byteorder))
result = b''.join(chunks)
return result
```
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue27096>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com