Open Kongduino opened 4 years ago
Indeed this is what Lora.random() produces :
highest values are 0x45, 0x47 ...
I also struggled with this and expected a random byte from this function. Thanks for the example @Kongduino
Can this be adjusted in the next version of the library?
LoRaClass::random() reads the register once and returns the byte.
This is wrong for two reasons:
1) LoRa chip must be set in a specific mode before that, you can't get random number at any given time. LoRa must be stopped and set to continuous mode first, and so on.
2) There should be 8 reads, keeping only the least significant bit (LSB), and build the output byte from that.
See Chapter 4 of Random Number Generation for Cryptography.
Example code from LoRandom.h
You need to put the SX1276/8 in Receive Continuous mode, SF7, C/R 4/5, BW 125KHz (call to
setupLoRandom()
, and then read 8 bytes to get one random byte (call togetLoRandomByte()
). After which you need to put back your LoRa chip to whatever settings you were using.In BastWAN_LoRa_RNG I build a buffer of 256 random bytes at once.