1
0
mirror of https://github.com/ThunderEX/py-kms.git synced 2025-04-19 18:22:22 +03:00
py-kms/upy/fakerandom.py
2017-08-18 20:09:51 +08:00

18 lines
407 B
Python

from urandom import *
import math
def randint(a, b):
while True:
r = getrandbits(math.ceil(math.log2(b - a)))
if r < b - a:
break
return a + r
def choice(seq):
"""Choose a random element from a non-empty sequence."""
try:
i = randint(0, len(seq))
except ValueError:
raise IndexError('Cannot choose from an empty sequence')
return seq[i]