-
Notifications
You must be signed in to change notification settings - Fork 7.6k
std::random_device always returns constant value #8201
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
Comments
Reproducible for me. Just had a quick look at cppreference and found this:
Also note you are creating a fresh But, yes, ESP32 does have hardware RNG so PRNG does not seem like an acceptable behavior. I think this is an STL's fault, not really Arduino SDK's. |
This behavior may be intentional. Possibly related: #7848. Does the issue occur for an older version, say 2.0.6? |
I haven't been able to test it on older versions yet, as the Visual Micro board manager only provides the option to install the newest version. |
This is not intentional, we have overlooked checking how this function is implemented in libstdc++. I would recommend opening a feature request in IDF for this, sounds like something we could support. |
Ok, I submitted a feature request in the IDF's repository. |
@Zhu-jiatong - As for Arduino related random functionality, #7848 has an example about how to generate pseudo and real random sequences using Arduino APIs. |
Board
Irrelevant
Device Description
ESP32 NodeMCU
Hardware Configuration
Bare ESP32 Board
Version
v2.0.9
IDE Name
Visual Micro (Arduino IDE)
Operating System
Windows 11
Flash frequency
80Mhz
PSRAM enabled
no
Upload speed
115200
Description
I intended to use a real random number generator for cryptographic purposes. So, I choose
std::random_device
, which should be a platform independent way that is able to return real random numbers.However, the generator produces the same value
3499211612
every time the ESP32 is powered on, which is not random.Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: