Skip to content

Instantly share code, notes, and snippets.

@Bak-Jin-Hyeong
Created June 12, 2019 10:17
Show Gist options
  • Save Bak-Jin-Hyeong/0a0334ad834e86ad4ed9caa8fa3bf361 to your computer and use it in GitHub Desktop.
Save Bak-Jin-Hyeong/0a0334ad834e86ad4ed9caa8fa3bf361 to your computer and use it in GitHub Desktop.
#ifndef SPLITMIX64__H__
#define SPLITMIX64__H__
#include <cstdint>
constexpr uint64_t splitmix64_stateless(uint64_t previous_state) noexcept
{
uint64_t z = previous_state + 0x9E3779B97F4A7C15ull;
z = (z ^ (z >> 30)) * 0xBF58476D1CE4E5B9ull;
z = (z ^ (z >> 27)) * 0x94D049BB133111EBull;
return z ^ (z >> 31);
}
class Splitmix64
{
public:
Splitmix64() noexcept = default;
Splitmix64(uint64_t seed) noexcept : state_(seed) {}
uint64_t next() noexcept
{
state_ += 0x9E3779B97F4A7C15ull;
uint64_t z = state_;
z = (z ^ (z >> 30)) * 0xBF58476D1CE4E5B9ull;
z = (z ^ (z >> 27)) * 0x94D049BB133111EBull;
return z ^ (z >> 31);
}
private:
uint64_t state_ = 0;
};
#endif // #ifndef SPLITMIX64__H__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment