Message266277
@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
``` |
|
Date |
User |
Action |
Args |
2016-05-24 21:01:49 | ideasman42 | set | recipients:
+ ideasman42, tim.peters, rhettinger, r.david.murray, serhiy.storchaka |
2016-05-24 21:01:49 | ideasman42 | set | messageid: <1464123709.76.0.67061687623.issue27096@psf.upfronthosting.co.za> |
2016-05-24 21:01:49 | ideasman42 | link | issue27096 messages |
2016-05-24 21:01:49 | ideasman42 | create | |
|