micropython-lib/random/random.py

19 wiersze
336 B
Python
Czysty Zwykły widok Historia

from urandom import *
def randrange(start, stop=None):
if stop is None:
stop = start
start = 0
upper = stop - start
bits = 0
pwr2 = 1
while upper > pwr2:
pwr2 <<= 1
bits += 1
while True:
r = getrandbits(bits)
if r < upper:
break
return r + start