#pragma once #include "EHS.h" namespace ehs { template class PRNG { private: T seed; T last; public: PRNG() : seed(0), last(0) { } PRNG(const T seed) : seed(seed), last(seed) { } PRNG(const PRNG& prng) : seed(prng.seed), last(prng.last) { } PRNG& operator=(const PRNG& prng) { if (this == &prng) return *this; seed = prng.seed; last = prng.last; return *this; } T Generate(const T min, const T max) { return Generate() % (max - min) + min; } T Generate() { return ((last = last * (T)214013 + (T)2531011) >> 16) & (T)0x7fff; } }; typedef PRNG PRNG_s64; typedef PRNG PRNG_u64; typedef PRNG PRNG_s32; typedef PRNG PRNG_u32; typedef PRNG PRNG_s16; typedef PRNG PRNG_u16; typedef PRNG PRNG_s8; typedef PRNG PRNG_u8; }