--- deliantra/server/common/utils.C 2007/01/18 22:19:59 1.41 +++ deliantra/server/common/utils.C 2007/01/19 22:24:10 1.43 @@ -39,14 +39,15 @@ #include -rand_gen rndm (time (0)); +rand_gen rndm; -tausworthe_random_generator::tausworthe_random_generator (uint32_t seed) +void +tausworthe_random_generator::seed (uint32_t seed) { - state [0] = max ( 2, seed * 69069U); - state [1] = max ( 8, state [0] * 69069U); - state [2] = max ( 16, state [1] * 69069U); - state [3] = max (128, state [2] * 69069U); + state [0] = max ( 2U, seed * 69069U); + state [1] = max ( 8U, state [0] * 69069U); + state [2] = max ( 16U, state [1] * 69069U); + state [3] = max (128U, state [2] * 69069U); for (int i = 11; --i; ) operator ()(); @@ -63,6 +64,19 @@ return state [0] ^ state [1] ^ state [2] ^ state [3]; } +uint32_t +tausworthe_random_generator::get_range (uint32_t r_max) +{ + return next () % r_max; +} + +// return a number within (min .. max) +int +tausworthe_random_generator::get_range (int r_min, int r_max) +{ + return r_min + (*this) (max (r_max - r_min + 1, 1)); +} + /* * The random functions here take luck into account when rolling random * dice or numbers. This function has less of an impact the larger the