-
-
Notifications
You must be signed in to change notification settings - Fork 7k
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
randomSeed: Bad/redundant "if" #3887
Comments
For seed== 0 // 0: a "real" randomized random seed based on system clock() Note that a PRNG initialized by a certain fixed value will always generate identical pseudo-random series to infinity, which can be used for code testing purposes - but which will not make much sense for common PRNG use! As Arduino boards don't provide a system clock - and
_(moreover, the Arduino API function names are not C compliant - |
Always nice to read some Vogon poetry ;-) For the time being, let's separate here the general discussion on PRNGs from the existing Arduino implementation. Given the current state, where randomSeed is essentially a wrapper to AVR-Libc's srandom, the if in the function seems erroneous. Can we do without it? |
IMO we actually needed to have srand(0) for "randomized" seeding and srand(-1) to restore the last random series |
@igendel, agreed, I cannot see any reason for treating "0" specially. The libc @vogonjeltz, you talk about |
yes, I only know the common cstdlib C commands srand ( (unsigned int)( millis() + AnalogRead(A0) ) ); About -1 I'm searching and will report... IIRC I once used it ... |
Proposal from #575: |
Hi,
In function
randomSeed
(WMath.cpp
, line 30) there's the codeSince "srandom" handles the value 0 itself (see for example its implementation in
random.c
of AVR-Libc*), it seems there's no need for that "if". Furthermore, it is undocumented and may break functionality - for instance, if a user wants to produce two identical pseudo-random sequences using the seed 0.If that "if" can be removed, it will save a byte or two.
See discussion about this here (not all of it directly relevant): https://forum.arduino.cc/t/randomseed-why-is-0-ignored/337424
Thanks,
The text was updated successfully, but these errors were encountered: