Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make random() and randomSeed() follow Arduino specification #7404

Closed
SuGlider opened this issue Oct 26, 2022 · 2 comments · Fixed by #7848
Closed

Make random() and randomSeed() follow Arduino specification #7404

SuGlider opened this issue Oct 26, 2022 · 2 comments · Fixed by #7848
Assignees
Milestone

Comments

@SuGlider
Copy link
Collaborator

  According to the Arduino API reference

https://www.arduino.cc/reference/en/language/functions/random-numbers/randomseed/

it should be possible to create a repeatable sequence of pseudo-random numbers based on the same seed being used.

This does not seem to work on ESP32. Poking around, it looks like it is implemented here

https://github.com/espressif/arduino-esp32/blob/5be3ff74ea6057c7ee35fcc0cd60defb82786ec3/cores/esp32/WMath.cpp

It looks like it is based on esp_random() which uses noise to more "truly" randomize numbers. This might seem like a good idea, but it actually breaks documented behavior. The spec even suggests:

"it can occasionally be useful to use pseudo-random sequences that repeat exactly."

I think it would be better to keep the defined Arduino behavior and give the user a way to opt for the ESP32 style randomization if desired, or perhaps documenting a technique to do so, such as setting a seed based on esp_random().

Originally posted by @rsiemens77 in #7399

@SuGlider
Copy link
Collaborator Author

Potential Solution in #7399 (comment)

@SuGlider
Copy link
Collaborator Author

The solution for ESP32 will follow the ESP8266 Arduino implementation and rational for random(), randomSeed() and secureRandom().

esp8266/Arduino#1710
esp8266/Arduino#2142
#7399

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging a pull request may close this issue.

2 participants