randomSeed() and repeatable 'random' number on ESP32
Posted: Mon Aug 17, 2020 2:33 pm
Code: Select all
long randNumber;
void setup() {
Serial.begin(9600);
randomSeed(140584);
delay(1000);
Serial.println("BEGIN HERE");
Serial.println("----------");
}
void loop() {
randNumber = random(101010100, 757575759);
Serial.println(randNumber);
delay(1000);
}
I used the code above and found that no matter what seed number I use the numbers are not repeatable, upon further research I found that the ESP32 has a true-random number generator by using the noise values on the WiFi/BLE chip, so that explains it.
This is one of the rare occurrences where the older pseudo-random functionality was more suited then true-random! By default the random() function calls esp_random() so I do not think it is possible to 'downgrade' and force the ESP32 to use seeded pseudo-random number sequences? I've been pulling my hair out with it.
May I ask if anyone has any advice? Many thanks, G