ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/rng.h
(Generate patch)

Comparing deliantra/server/include/rng.h (file contents):
Revision 1.1 by root, Fri Jul 2 02:00:47 2010 UTC vs.
Revision 1.2 by root, Tue Jul 6 20:00:46 2010 UTC

131// this is actually an adaptor that provides different types 131// this is actually an adaptor that provides different types
132// of random numbers. 132// of random numbers.
133template<class generator> 133template<class generator>
134struct random_number_generator : generator 134struct random_number_generator : generator
135{ 135{
136 random_number_generator ()
137 {
138 }
139
140 random_number_generator (uint32_t seed)
141 {
142 this->seed (seed);
143 }
144
136 // uniform distribution, [0 .. num - 1] 145 // uniform distribution, [0 .. num - 1]
137 uint32_t operator ()(uint32_t num) 146 uint32_t operator ()(uint32_t num)
138 { 147 {
139 return !is_constant (num) ? get_range (num) // non-constant 148 return !is_constant (num) ? get_range (num) // non-constant
140 : num & (num - 1) ? (this->next () * (uint64_t)num) >> 32U // constant, non-power-of-two 149 : num & (num - 1) ? (this->next () * (uint64_t)num) >> 32U // constant, non-power-of-two
164}; 173};
165 174
166// the default rng used in the game 175// the default rng used in the game
167typedef random_number_generator<freeciv_random_generator> rand_gen; 176typedef random_number_generator<freeciv_random_generator> rand_gen;
168 177
178// used when we often seed
179typedef random_number_generator<tausworthe_random_generator> seedable_rand_gen;
180
169extern rand_gen rndm, rmg_rndm; 181extern rand_gen rndm, rmg_rndm;
170 182
171#endif 183#endif
172 184

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines