Skip to content

why don't random() and randomSeed() conform to Arduino specifications? #7399

Answered by igrr
rsiemens77 asked this question in Q&A
Discussion options

You must be logged in to vote

Well spotted @rsiemens77!

This issue also used to exist in the ESP8266 Arduino core. On one hand, some libraries in the Arduino ecosystem used the random function inappropriately to generate some secrets or keys, hence it was desirable to make the source of these numbers truly random. On the other hand, there was the concern you have mentioned — sometimes it's desirable to have a repeatable pseudorandom sequence, for example in games.

The solution which was implemented in the ESP8266 Arduino core was to use the HW RNG unless randomSeed function was called. This was based on the observation that libraries didn't usually call randomSeed, and only called random. So calling randomSeed was an …

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@rsiemens77
Comment options

Answer selected by pedrominatel
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants