Git Product home page Git Product logo

Comments (2)

bryc avatar bryc commented on August 16, 2024

Hmm, thanks for bringing this up. Agreed, this is confusing.

Well I can't find a definitive source of the constants I chose before Aug 2018. Either the original source is lost or hidden, or it is entirely possible that I came up with this variant myself when posting on StackOverflow, either intentionally or accidentally.

Here's some background. I remember being interested in a SplitMix32 function after learning about SplitMix64.

I originally posted that particular function as C code on StackOverflow on Aug 28, 2018 at 10:55 as follows:

"SplitMix32", adopted from xxHash/MurmurHash3 (Weyl sequence):

uint32_t splitmix32(void) {
    uint32_t z = state += 0x3504f333;
    z ^= z >> 15; // 16 for murmur3
    z *= 0x85ebca6b;
    z ^= z >> 13;
    z *= 0xc2b2ae3d; // 0xc2b2ae35 for murmur3
    return z ^= z >> 16;
}

Interestingly, in this initial version, the first constant is the one from MurmurHash3, but the second one was initially xxHash. After just one day I edited the post, changing the second constant to match MurmurHash3. But I left the 15. It also seems that this might be the source people are taking this function from.

The changed function for reference:

uint32_t splitmix32(void) {
    uint32_t z = state += 0x9e3779b9;
    z ^= z >> 15; // 16 for murmur3
    z *= 0x85ebca6b;
    z ^= z >> 13;
    z *= 0xc2b2ae35;
    return z ^= z >> 16;
}

Someone independently took note of this variant and seemed to have found it's slightly better than the original:

A seemingly popular variation of SplitMix32 changes the first bitshift length from 16 to 15. It is included under the name splitmix32a in this repository, and fares slightly better than plain splitmix32 in Crush and BigCrush tests (5 or 4 failures in Crush, 9 in BigCrush). In PractRand, this variation fails during the 1 GB stage, whereas plain splitmix32 fails in the preceding 512 MB round.

I suppose if it is technically better as a PRNG, that's a silver lining. Though I truly cannot remember if I had a good reason to change the constants.

He also mentions an additional splitmix32b variant with even more slightly better statistics.

Anyway, as far as resolving this issue - I could restore the shift value to 16, or I could simply add a note that says "the shift value of 15 apparently performs slightly better in testing, but I have no clue why". Let me know if you have any further thoughts.

from code.

bryc avatar bryc commented on August 16, 2024

Closing issue. I just added a note to clarify that the constants tend to change between implementations, and that certain constants perform better than the original MurmurHash3 constants.

from code.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.