""" |
"""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'] |
|
|
|
|
import sys, os, time |
import sys, os, time |
from whrandom import random, seed |
random = __import__('random',{}).random # from _.random import random |
seeded = 0 |
seeded = 0 |
|
|
try: |
try: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 random. |
Don't trust this for crypto, though! |
Don't trust this for crypto, though! |
""" |
""" |
|
|
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]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|