Random numbers: the urandom module

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
User avatar
Posts: 2163
Joined: Fri Jul 18, 2014 8:01 am
Location: UK

Random numbers: the urandom module

Post by pythoncoder » Mon Dec 19, 2016 7:43 am

Questions have been raised regarding producing random numbers on platforms lacking the Pyboard's hardware random number generator.
The module urandom supports a pseudorandom number generator via the getrandbits function. This returns an n-bit pseudorandom number. urandom.getrandbits(30) works in a similar way to pyb.rng().

Note that pyb.rng() returns hardware generated true random numbers, whereas the output of getrandbits is deterministic.
Peter Hinch

Post Reply