Seed PRNGs from System source instead of time #4789
Merged
+28
−15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #4596.
Now PCG32 has
new
without parameters (that creates seed AND sequence from system source giving 128 bits of enthropy) andnew
that was here before, that receives 64-bits seed and sequence that is 0 by default.For an ISAAC I just replaced default value in constructor. Perhaps complex initialization isn't needed because seed values are already "random" enough (so they can be directly copied to state), but it won't hurt and copying won't improve the performance much (as slowest thing is getting random from system source).
Random.new_seed
is removed, because PCG32 needs 64-bit int, ISAAC needs a buffer, so I think it is cleaner to generate them in corresponding modules.About performance - as was mentioned in a #4596 this change slows down creating of PRNGs a lot (up to x50 times). But i think improved safety pays for it because creation of PRNG doesn't seem time-critical operation. Creating from given seed isn't affected, only from "unpredictable" seed.