ESP32 + randomseed(10) should return each start the same random numbers?

Hey Folks

I'm using an ESP32. The sequence of numbers is different after each startup.
According to other forum entrys, the return value should always be the same?

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("Hello, ESP32!");
  randomSeed(10);
}

void loop() {
  // put your main code here, to run repeatedly:
  int rnd = random(1, 7);
  Serial.println(rnd);
  delay(1000); // this speeds up the simulation
}

What do i mixed here up?

thanks for you help

Hi,
What happens if you use a random seed between 1 and 7 instead of 10 which is outside?
I don't see your problem, it is a proper random response.

If you need an array of particular numbers, then generate an array.

Tom.... :smiley: :+1: :coffee: :australia:

1 Like

the ESP32 has a true Random Number Generator (generated based on the noise of the WiFi / Bluetooth RF subsystem) and does not rely on mathematical series

possibly if you shut the WiFi and BT down then you'll get the same sequence

Side note: your question was also raised here (no answer)

2 Likes

ESP32's Random number generator API, Random Number Generation - ESP32 - — ESP-IDF Programming Guide latest documentation.

2 Likes

here you go - the full doc and no guess work :slight_smile:

thx for the link

2 Likes

try skip using randomSeed()

(just for esp8266 and esp32)

i was searching for another issue and casually looked the source code for esp8266... and noticed when randomSeed() was NEVER used, random() uses the hardware random generator instead

additionally in arduino, readAnalog() on a not initialized pin (for randomSeed()) does not generate enough noise and the result is a very short range of numbers... i am searching for the "von newmann" technique but couldn't find it :frowning:

EDIT: i found it here = The reliable but not very sexy way to seed random - #29 by utopia

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.