This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ideasman42
Recipients ideasman42, r.david.murray, rhettinger, serhiy.storchaka, tim.peters
Date 2016-05-24.21:01:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1464123709.76.0.67061687623.issue27096@psf.upfronthosting.co.za>
In-reply-to
Content
@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
```
History
Date User Action Args
2016-05-24 21:01:49ideasman42setrecipients: + ideasman42, tim.peters, rhettinger, r.david.murray, serhiy.storchaka
2016-05-24 21:01:49ideasman42setmessageid: <1464123709.76.0.67061687623.issue27096@psf.upfronthosting.co.za>
2016-05-24 21:01:49ideasman42linkissue27096 messages
2016-05-24 21:01:49ideasman42create