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
Bug? VERY predictable output from random() #11811
Labels
Comments
per1234
added
Component: Core
Related to the code for the standard Arduino API
Type: Bug
labels
Jul 26, 2022
atom-smasher
added a commit
to atom-smasher/esp8266_beaconSpam
that referenced
this issue
Jul 27, 2022
Added functionality to handle 20,000+ SSIDs using "classic" (sequential) MAC addresses; I was only able to compile a little over 23,000 SSID names for testing. This requires the 4th and 5th octets of the MAC address to roll-over, as needed. Changed how the PRNG is seeded, using "mayhem" mode, account of this bug - arduino/Arduino#11811
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
VERY predictable output from random(), after being seeded with an incrementing counter.
Attached sketch shows how I'm getting four streams of almost perfectly sequential numbers from an algorithm that uses multiple calls to random() after using an incrementing counter as a seed via randomSeed(). It should not be possible to get anything orderly from that, especially over such an immediately short period.
The sketch (below) produces mac-addresses as my original script does, then has four columns: The first three columns show sequential numbers from the high-byte of the last octet, the fourth column shows sequential numbers from the low-byte of the last octet.
Right from the start, with seed 0xb53fdfdf:
That's seeded with 0x3ffe883c, and that output is near the beginning.
The first three columns to the right of the MAC addresses all show the high-byte of the last octet:
The 4th column counts the low-byte of the last octet over a longer period, but the whole pattern repeats almost perfectly, and seemingly indefinitely, regardless of how it's seeded. Not the behaviour I expect from a PRNG!
Just looking at the "random" MAC addresses I was wanting, it's obvious that the low-byte of the last octet is repeating for 14-15 times (14.7, on average) and then incrementing. Again, should be 100% impossible to get this from any self-respecting PRNG being seeded by a counter.
nb the sketch has a delay() towards the bottom, so it scrolls up on a console at human-readable speed. For data-collection, just comment out the delay.
nb2 the random seed can be set manually.
sketch:
Edited to correct how the seed is displayed, and share output with a verified seed.
The text was updated successfully, but these errors were encountered: