-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
zero argument srand() #8313
Comments
And the test/random.jl file must be changed to use this function: |
No, automated tests should always be deterministic. |
To elaborate a little less tersely now that I'm not on a phone with a monthly cap on internet data, there are two purposes for randomized testing:
For the former use case, you should absolutely use truly random values and many of them until you're convinced that your algorithm is in fact correct. The latter use case is the only thing that automated tests are for and you absolutely do not want random failures – you want to pick some seed that is known to pass and make sure that it continues to pass. |
move Base.random.__init__ to zero-arg srand(); fixes #8313
Oh I consciously decided in my last comment to use less often statements like "IIUC"/"I guess"/"maybe"/... ;-) |
In particular, what made me think
I didn't understand well the comment (do we go back to nondeterminism?), but I really thought that |
@rfourquet The point of those tests seem to be to ensure that |
If a test should always pass regardless of what random values are produced, then it's ok to call it on changing random values but you do want to record what they were for later inspection in case the tests fail. This is different than stochastic tests that are expected to fail some of the time – statistical tests are notoriously of this variety. Those should only be run automatically with some set of known good values to prevent regressions. |
OK thanks, I knew close to nothing about stochastic tests. But I think I understand now the source of my confusion:
So I see 2 bugs: code which doesn't need/want srand inserted after the "leave nondeterminism" (without calling So I will issue a PR with test code that plays with srand(constant) at the end of the file, so that the first part is non-determinist. |
In fact the first "bug" I mentioned is not really a bug but again the comment "leave nondeterminism" is slightly misleading: there were repeated calls to |
Currently we initialize our RNG only when the Random module is loaded, but in some situations it might be useful to reseed the RNG with good entropy from the OS.
@rfourquet suggested in #8309 that the logic form
Base.Random.__init__()
in base/random.jl is moved to a zero argumentsrand()
, so that it becomes easier to use.I think that is a good idea.
The text was updated successfully, but these errors were encountered: