Skip to content
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

Add function to instantiate seeded MTRng #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

emallson
Copy link

This PR consists of two parts:

  1. Added a function mersenne() that creates an instance of MTRng seeded with the next u64 from the OsRng. This makes it easier to drop-in replace this library in code that uses thread_rng() and Rng-passing style (i.e. creating a single thread_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 the MTRng instance). Taking the next random u64 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 to mersenne() are made simultaneously (e.g. one on each thread), they will have distinct seeds.

  2. 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).

Generating 100 u64s was overkill for initializing. 64 bits of entropy
from the OS is generally enough.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant