""" |
"""Obtain bytes of random data with varying degrees of quality, |
Obtain bytes of random data with varying degrees of quality, using |
using OS facilities for high-quality entropy if available.""" |
OS facilities for high-quality entropy if available. |
|
""" |
|
|
|
__all__ = ['randbytes', 'rand16'] |
__all__ = ['randbytes', 'rand16'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lasthash = seedhash = '' |
lasthash = seedhash = '' |
|
|
def prng_some(): |
def prng_some(): |
prng_some() |
prng_some() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def prng(nbytes): |
def prng(nbytes): |
""" |
""" |
A PRNG that hopefully is better than just using whrandom. |
A PRNG that hopefully is better than just using whrandom. |
return None |
return None |
|
|
|
|
|
|
|
|
|
|
|
|
funcs = { |
funcs = { |
#(prng, wait) : function |
#(prng, wait) : function |
|
|
# through python, it should be added here. XXX |
# through python, it should be added here. XXX |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def randbytes(nbytes, prng=1, wait=0): |
def randbytes(nbytes, prng=1, wait=0): |
""" |
""" |
Get nbytes number of bytes of randomness if possible. |
Get nbytes number of bytes of randomness if possible. |
|
|
s = randbytes(2, prng, wait) |
s = randbytes(2, prng, wait) |
return (ord(s[0]) << 8) | ord(s[1]) |
return (ord(s[0]) << 8) | ord(s[1]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|