Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdint>
- using u32 = std::uint32_t;
- class Random {
- public:
- Random() = default;
- void reset(u32 seed) {
- *this = {};
- do {
- a = 0x4F6CDD1D * (a ^ seed ^ ((a ^ seed) >> 0x15) ^ ((a ^ seed ^ ((a ^ seed) >> 0x15)) >> 4));
- b = 0x4F6CDD1D * (b ^ seed ^ ((b ^ seed) >> 0x15) ^ ((b ^ seed ^ ((b ^ seed) >> 0x15)) >> 4));
- c = 0x4F6CDD1D * (c ^ seed ^ ((c ^ seed) >> 0x15) ^ ((c ^ seed ^ ((c ^ seed) >> 0x15)) >> 4));
- d = 0x4F6CDD1D * (d ^ seed ^ ((d ^ seed) >> 0x15) ^ ((d ^ seed ^ ((d ^ seed) >> 0x15)) >> 4));
- } while (!(a | b | c | d));
- }
- u32 getRandomU32() {
- const u32 s = a ^ (a << 0xB) ^ ((a ^ (a << 0xB)) >> 8) ^ d;
- const u32 new_c = s ^ (d >> 0x13);
- const u32 new_d = (b ^ (b << 0xB) ^ ((b ^ (b << 0xB)) >> 8) ^ new_c) ^ (s >> 0x13);
- a = c;
- b = d;
- c = new_c;
- d = new_d;
- return c;
- }
- static Random& sInstance;
- private:
- u32 a = 0x75BCD15;
- u32 b = 0x159A55E5;
- u32 c = 0x1F123BB5;
- u32 d = 0x5491333;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement