Skip to content

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

Closed
@SuGlider

Description

@SuGlider
  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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions