urandom.randint() replacement?
urandom.randint() replacement?
I want to generate a random number between 0 and 360. However, urandom only has getrandbits() implemented. Any other clean way in Micropython to do what i'm trying to achieve?
Re: urandom.randint() replacement?
Not sure where I found it...
Code: Select all
import urandom
def randint(min, max):
span = max - min + 1
div = 0x3fffffff // span
offset = urandom.getrandbits(30) // div
val = min + offset
return val