--- deliantra/server/include/util.h 2010/06/29 16:52:53 1.109 +++ deliantra/server/include/util.h 2010/07/02 02:00:47 1.110 @@ -431,89 +431,6 @@ } }; -// P. L'Ecuyer, “Maximally Equidistributed Combined Tausworthe Generators”, Mathematics of Computation, 65, 213 (1996), 203–213. -// http://www.iro.umontreal.ca/~lecuyer/myftp/papers/tausme.ps -// http://www.iro.umontreal.ca/~lecuyer/myftp/papers/tausme2.ps -struct tausworthe_random_generator -{ - uint32_t state [4]; - - void operator =(const tausworthe_random_generator &src) - { - state [0] = src.state [0]; - state [1] = src.state [1]; - state [2] = src.state [2]; - state [3] = src.state [3]; - } - - void seed (uint32_t seed); - uint32_t next (); -}; - -// Xorshift RNGs, George Marsaglia -// http://www.jstatsoft.org/v08/i14/paper -// this one is about 40% faster than the tausworthe one above (i.e. not much), -// despite the inlining, and has the issue of only creating 2**32-1 numbers. -// see also http://www.iro.umontreal.ca/~lecuyer/myftp/papers/xorshift.pdf -struct xorshift_random_generator -{ - uint32_t x, y; - - void operator =(const xorshift_random_generator &src) - { - x = src.x; - y = src.y; - } - - void seed (uint32_t seed) - { - x = seed; - y = seed * 69069U; - } - - uint32_t next () - { - uint32_t t = x ^ (x << 10); - x = y; - y = y ^ (y >> 13) ^ t ^ (t >> 10); - return y; - } -}; - -template -struct random_number_generator : generator -{ - // uniform distribution, [0 .. num - 1] - uint32_t operator ()(uint32_t num) - { - return !is_constant (num) ? get_range (num) // non-constant - : num & (num - 1) ? (this->next () * (uint64_t)num) >> 32U // constant, non-power-of-two - : this->next () & (num - 1); // constant, power-of-two - } - - // return a number within the closed interval [min .. max], max can be >, < or == min. - int operator () (int r_min, int r_max) - { - return is_constant (r_min <= r_max) && r_min <= r_max - ? r_min + operator ()(r_max - r_min + 1) - : get_range (r_min, r_max); - } - - // return a number within the half-open interval [0..1[ - double operator ()() - { - return this->next () / (double)0x100000000ULL; - } - -protected: - uint32_t get_range (uint32_t r_max); - int get_range (int r_min, int r_max); -}; - -typedef random_number_generator rand_gen; - -extern rand_gen rndm, rmg_rndm; - INTERFACE_CLASS (attachable) struct refcnt_base {