> The problem is AFAICT there's currently no way to get a file
> descriptor to the underlying /dev/urandom (and I don't know how it
> works on Windows).
We can reimplement os.urandom in SystemRandom on UNIX to keep the file (fd)
open. The code is very simple, basically it's just a call to file.read(n).
Adding a randbytes() method in Python 3.5 would be nice.
The io module can handle boring things for you, like calling read in a loop
until you get enough bytes and handle InterruptError.
Except if you would prefer to use os.read or FileIO.read to avoid readahead. |