Skip to content

Functions to generate random numbers from rapidhash #28

@wigging

Description

@wigging

The wyhash repo (which rapidhash evolved from) provides wyrand, wy2u01, and wy2gau functions for generating random numbers. The code for these functions is shown below. What are the equivalent functions for rapidhash?

// The wyrand PRNG that pass BigCrush and PractRand
static inline uint64_t wyrand(uint64_t *seed) {
    *seed += 0x2d358dccaa6c78a5ull;
    return _wymix(*seed, *seed ^ 0x8bb84b93962eacc9ull);
}

// Convert any 64 bit pseudo random numbers to uniform distribution [0,1). It can be combined with
// wyrand, wyhash64 or wyhash.
static inline double wy2u01(uint64_t r) {
    const double _wynorm = 1.0 / (1ull << 52);
    return (r >> 12) * _wynorm;
}

// Convert any 64 bit pseudo random numbers to APPROXIMATE Gaussian distribution. It can be combined
// with wyrand, wyhash64 or wyhash.
static inline double wy2gau(uint64_t r) {
    const double _wynorm = 1.0 / (1ull << 20);
    return ((r &0x1fffff) + ((r >> 21) &0x1fffff) + ((r >> 42) &0x1fffff)) * _wynorm - 3.0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions