Add function to instantiate seeded MTRng #2
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.
This PR consists of two parts:
Added a function
mersenne()
that creates an instance of MTRng seeded with the nextu64
from theOsRng
. This makes it easier to drop-in replace this library in code that usesthread_rng()
andRng
-passing style (i.e. creating a singlethread_rng()
and then passing it to child functions rather than making new instances on-demand), because seeding is already handled (so it is again a one-liner instead of several lines and imports to generate the seed and then theMTRng
instance). Taking the next randomu64
is done instead of using e.g. the current time because this guarantees that even when multiple instances of a program start at once or when multiple calls tomersenne()
are made simultaneously (e.g. one on each thread), they will have distinct seeds.Added the remaining 910 values to the MT64 test vector. This was just something I did to triple-check the implementation. The test still passes with no changes to the implementation, this just makes the sequence of numbers used match the official test list.
(There are some other changes that are the result of
rustfmt
running automatically on the project due to my editor setup).