Rapidhash RNG algorithm#114
Open
JayceFayne wants to merge 2 commits intosmol-rs:masterfrom
Open
Conversation
Author
|
rapidhash's MSRV is 1.71. If there is interest in moving from wyhash to rapidhash I can port the code to the current fastrand MSRV |
|
Has there been any progress on this? |
taiki-e
reviewed
May 3, 2026
Collaborator
taiki-e
left a comment
There was a problem hiding this comment.
-
We want to avoid situations where the output differs across platforms even when the seed is the same, because there are use cases like #20.
-
How does the portable Rapidhash RNG differ from wyrand? The constants and the processing performed there are the same, right?
- https://github.com/hoxxep/rapidhash/blob/v4.4.1/rapidhash/src/rng.rs
const RAPID_SECRET: [u64; 3] = [0x2d358dccaa6c78a5, 0x8bb84b93962eacc9, 0x4b33a62ed433d4a3];
#[inline] pub fn rapidrng_fast(seed: &mut u64) -> u64 { *seed = seed.wrapping_add(RAPID_SECRET[0]); rapid_mix::<false>(*seed, *seed ^ RAPID_SECRET[1]) }
- https://github.com/hoxxep/rapidhash/blob/v4.4.1/rapidhash/src/util/mix.rs
#[inline(always)] #[must_use] pub(crate) const fn rapid_mix<const PROTECTED: bool>(a: u64, b: u64) -> u64 { let r = (a as u128).wrapping_mul(b as u128); if !PROTECTED { (r as u64) ^ (r >> 64) as u64 } else { (a ^ r as u64) ^ (b ^ (r >> 64) as u64) } }
Lines 148 to 159 in 6c4e800
- https://github.com/hoxxep/rapidhash/blob/v4.4.1/rapidhash/src/rng.rs
To be honest, it’s odd if they’re claiming things have improved when nothing has actually changed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Replaces the current wyhash RNG algorithm with rapidhash.
The last commit can be dropped if the output (given the same seed) should be stable across different platforms.
closes #69