Skip to content

Instantly share code, notes, and snippets.

@stevefan1999-personal
Created July 31, 2025 02:59
Show Gist options
  • Select an option

  • Save stevefan1999-personal/2c99d1de66d18ef0af4e970b49005942 to your computer and use it in GitHub Desktop.

Select an option

Save stevefan1999-personal/2c99d1de66d18ef0af4e970b49005942 to your computer and use it in GitHub Desktop.
biski64 C++ implementation
struct biski64 {
uint64_t fast_loop{};
uint64_t mix{};
uint64_t loop_mix{};
static constexpr uint64_t splitmix64(uint64_t& x) { // NOLINT
uint64_t z = (x += 0x9e3779b97f4a7c15uLL);
z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9uLL;
z = (z ^ (z >> 27)) * 0x94d049bb133111ebuLL;
return z ^ (z >> 31);
}
constexpr biski64() : biski64(0) {}
constexpr explicit biski64(uint64_t seed) {
// It is the caller's responsibility to ensure 'state' is not NULL.
uint64_t seeder_state = seed;
// Derive initial values for each biski64 state variable.
mix = splitmix64(seeder_state);
loop_mix = splitmix64(seeder_state);
fast_loop = splitmix64(seeder_state);
for (int i = 0; i < 16; ++i) {
operator()();
}
}
using result_type = uint64_t;
static constexpr uint64_t min() { return std::numeric_limits<uint64_t>::min(); }
static constexpr uint64_t max() { return std::numeric_limits<uint64_t>::max(); }
static constexpr uint64_t rotate_left(uint64_t x, int k) { return (x << k) | (x >> (-k & 63)); }
constexpr uint64_t operator()() {
const uint64_t output = mix + loop_mix;
const uint64_t old_loop_mix = loop_mix;
loop_mix = fast_loop ^ mix;
mix = rotate_left(mix, 16) + rotate_left(old_loop_mix, 40);
fast_loop += 0x9999999999999999ULL; // Additive constant for the Weyl sequence.
return output;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment