ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/utils.C
(Generate patch)

Comparing deliantra/server/common/utils.C (file contents):
Revision 1.83 by root, Sun Dec 28 06:59:26 2008 UTC vs.
Revision 1.84 by root, Tue Dec 30 07:24:16 2008 UTC

51 state [1] = state [0] * 69069U; if (state [0] < 8U) state [0] += 8U; 51 state [1] = state [0] * 69069U; if (state [0] < 8U) state [0] += 8U;
52 state [2] = state [1] * 69069U; if (state [0] < 16U) state [0] += 16U; 52 state [2] = state [1] * 69069U; if (state [0] < 16U) state [0] += 16U;
53 state [3] = state [2] * 69069U; if (state [0] < 128U) state [0] += 128U; 53 state [3] = state [2] * 69069U; if (state [0] < 128U) state [0] += 128U;
54 54
55 for (int i = 11; --i; ) 55 for (int i = 11; --i; )
56 operator ()(); 56 next ();
57} 57}
58 58
59uint32_t 59uint32_t
60tausworthe_random_generator::next () 60tausworthe_random_generator::next ()
61{ 61{
65 state [3] = ((state [3] & 0xFFFFFF80U) << 13U) ^ (((state [3] << 3U) ^ state [3]) >> 12U); 65 state [3] = ((state [3] & 0xFFFFFF80U) << 13U) ^ (((state [3] << 3U) ^ state [3]) >> 12U);
66 66
67 return state [0] ^ state [1] ^ state [2] ^ state [3]; 67 return state [0] ^ state [1] ^ state [2] ^ state [3];
68} 68}
69 69
70template<class generator>
70uint32_t 71uint32_t
71tausworthe_random_generator::get_range (uint32_t num) 72random_number_generator<generator>::get_range (uint32_t num)
72{ 73{
73 return (next () * (uint64_t)num) >> 32U; 74 return (this->next () * (uint64_t)num) >> 32U;
74} 75}
75 76
76// return a number within (min .. max) 77// return a number within (min .. max)
78template<class generator>
77int 79int
78tausworthe_random_generator::get_range (int r_min, int r_max) 80random_number_generator<generator>::get_range (int r_min, int r_max)
79{ 81{
80 return r_min + get_range (max (r_max - r_min + 1, 0)); 82 return r_min + get_range (max (r_max - r_min + 1, 0));
81} 83}
84
85template struct random_number_generator<tausworthe_random_generator>;
86template struct random_number_generator<xorshift_random_generator>;
82 87
83/* 88/*
84 * The random functions here take luck into account when rolling random 89 * The random functions here take luck into account when rolling random
85 * dice or numbers. This function has less of an impact the larger the 90 * dice or numbers. This function has less of an impact the larger the
86 * difference becomes in the random numbers. IE, the effect is lessened 91 * difference becomes in the random numbers. IE, the effect is lessened

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines