pico-sdk
pico-sdk copied to clipboard
API to support generate random number?
is there a plan to add hardware random number generation?
Are you looking for "2.17.5. Random Number Generator" in https://datasheets.raspberrypi.org/rp2040/rp2040-datasheet.pdf ? Or are you asking for a "nice API" to wrap that?
You can read the ring oscillator random bit with something like
#include "hardware/structs/rosc.h"
bool get_random_bit() {
return rosc_hw->randombit;
}
This is just an unconditioned ring oscillator sample. It's not well characterised, somewhat biased, output is somewhat periodic when sampled rapidly, etc. We haven't wrapped it up in a simplified API because that might give an impression of randomness guarantees that we haven't done the characterisation to back up. It's very much "some assembly required".
What functionality are you looking for exactly?
See also the discussion about randomness on the forums.
Thank you very much for your example and forum discussions. I will use the rand number for the SSL library port. I can understand the hardware characteristic is not defined yet, but providing such a API is still useful and can be a seed feed to srand
~~This is fixed thanks to #4213. You can generate randomness on the RP2040 using os.urandom .~~
@makeworld-the-better-one It sounds like you might be mixing up the RP2040 C SDK with the RP2040 MicroPython port?
Yep sorry, my bad
This seems like a useful addition, as the random bit is not sufficiently random if polled at high frequency
Thank you very much for your example and forum discussions. I will use the rand number for the SSL library port. I can understand the hardware characteristic is not defined yet, but providing such a API is still useful and can be a seed feed to srand
You did see the note in the forums? "The datsheet does say that the randomness is not suitable for cryptography, since it can be compromised, and thus is only suitable for less critical applications."
fixed by #1111
merged into develop