You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
see other personal code that uses alternative system random (os.urandom)
try:
from secrets import choice, randbelow # Python 3.6 module
except ImportError:
import random as _py_random
random = _py_random # backup(, backup) plan
# Potentially overkill, use system random numbers
# Nested exception catching for older Python version
try:
try:
random = _py_random.SystemRandom()
except NotImplementedError:
# not available
pass
except AttributeError:
# Pre Python 2.4
pass
def randbelow(x):
return random.randint(0, x)
choice = random.choice
For completeness, (Linux) should not be needed:
try:
urandom = os.urandom
except AttributeError:
if os.path.exists('/dev/urandom'):
def urandom(n):
# UNIX ONLY
f = open('/dev/urandom')
result = f.read(n)
f.close()
return result
else:
def urandom(n):
s = []
for i in xrange(n):
r = random.randint(0,255)
s.append(chr(r))
return ''.join(s)
Windows only:
win32prng.getRandomBytes
The text was updated successfully, but these errors were encountered:
Py 3.6 >= https://docs.python.org/3/library/secrets.html#module-secrets -
secrets.token_bytes()
https://www.pycryptodome.org/src/random/random#Crypto.Random.get_random_bytes
see other personal code that uses alternative system random (os.urandom)
For completeness, (Linux) should not be needed:
Windows only:
The text was updated successfully, but these errors were encountered: