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

Please consider using a reproducible Rng instead of SmallRng #305

Open
jcowgill opened this issue Jan 8, 2024 · 0 comments
Open

Please consider using a reproducible Rng instead of SmallRng #305

jcowgill opened this issue Jan 8, 2024 · 0 comments

Comments

@jcowgill
Copy link

jcowgill commented Jan 8, 2024

I noticed that phf generates different maps depending on which platform you run the generator on. 32-bit and 64-bit platforms don't match. I tracked this down to SmallRng generating different keys in phf_generator/src/lib.rs. I think it would be useful if phf was reproducible and generated the same output on all platforms. This should be possible by switching to a fixed random number generator instead of using one of the default generators from the rand crate.


The docs for SmallRng say:

Furthermore, SmallRng is not a good choice when:

  • Portability is required. Its implementation is not fixed.

At at the module level it says:

PRNGs: Several companion crates are available, providing individual or families of PRNG algorithms. These provide the implementations behind StdRng and SmallRng but can also be used directly, indeed should be used directly when reproducibility matters.

I originally saw this in https://github.com/humenda/isolang-rs - it commits the output of phf_codegen to git and uses a test to verify the output hasn't changed. The test fails on 32-bit platforms due to this issue.

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

No branches or pull requests

1 participant