Skip to content

Rapidhash RNG algorithm#114

Open
JayceFayne wants to merge 2 commits intosmol-rs:masterfrom
JayceFayne:rapidhash
Open

Rapidhash RNG algorithm#114
JayceFayne wants to merge 2 commits intosmol-rs:masterfrom
JayceFayne:rapidhash

Conversation

@JayceFayne
Copy link
Copy Markdown

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

@JayceFayne
Copy link
Copy Markdown
Author

JayceFayne commented Oct 21, 2025

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

@ofek
Copy link
Copy Markdown

ofek commented Mar 20, 2026

Has there been any progress on this?

Copy link
Copy Markdown
Collaborator

@taiki-e taiki-e left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 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?

    fastrand/src/lib.rs

    Lines 148 to 159 in 6c4e800

    #[inline]
    fn gen_u64(&mut self) -> u64 {
    // Constants for WyRand taken from: https://github.com/wangyi-fudan/wyhash/blob/master/wyhash.h#L151
    // Updated for the final v4.2 implementation with improved constants for better entropy output.
    const WY_CONST_0: u64 = 0x2d35_8dcc_aa6c_78a5;
    const WY_CONST_1: u64 = 0x8bb8_4b93_962e_acc9;
    let s = self.0.wrapping_add(WY_CONST_0);
    self.0 = s;
    let t = u128::from(s) * u128::from(s ^ WY_CONST_1);
    (t as u64) ^ (t >> 64) as u64
    }

To be honest, it’s odd if they’re claiming things have improved when nothing has actually changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Alternative Hash (ex : highway, xxh3)

3 participants