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.41 by root, Thu Jan 18 22:19:59 2007 UTC vs.
Revision 1.42 by root, Fri Jan 19 15:15:49 2007 UTC

37#include <funcpoint.h> 37#include <funcpoint.h>
38#include <material.h> 38#include <material.h>
39 39
40#include <glib.h> 40#include <glib.h>
41 41
42rand_gen rndm (time (0)); 42rand_gen rndm;
43 43
44void
44tausworthe_random_generator::tausworthe_random_generator (uint32_t seed) 45tausworthe_random_generator::seed (uint32_t seed)
45{ 46{
46 state [0] = max ( 2, seed * 69069U); 47 state [0] = max ( 2, seed * 69069U);
47 state [1] = max ( 8, state [0] * 69069U); 48 state [1] = max ( 8, state [0] * 69069U);
48 state [2] = max ( 16, state [1] * 69069U); 49 state [2] = max ( 16, state [1] * 69069U);
49 state [3] = max (128, state [2] * 69069U); 50 state [3] = max (128, state [2] * 69069U);
59 state [1] = ((state [1] & 0xFFFFFFF8U) << 2U) ^ (((state [1] << 2U) ^ state [1]) >> 27U); 60 state [1] = ((state [1] & 0xFFFFFFF8U) << 2U) ^ (((state [1] << 2U) ^ state [1]) >> 27U);
60 state [2] = ((state [2] & 0xFFFFFFF0U) << 7U) ^ (((state [2] << 13U) ^ state [2]) >> 21U); 61 state [2] = ((state [2] & 0xFFFFFFF0U) << 7U) ^ (((state [2] << 13U) ^ state [2]) >> 21U);
61 state [3] = ((state [3] & 0xFFFFFF80U) << 13U) ^ (((state [3] << 3U) ^ state [3]) >> 12U); 62 state [3] = ((state [3] & 0xFFFFFF80U) << 13U) ^ (((state [3] << 3U) ^ state [3]) >> 12U);
62 63
63 return state [0] ^ state [1] ^ state [2] ^ state [3]; 64 return state [0] ^ state [1] ^ state [2] ^ state [3];
65}
66
67uint32_t
68tausworthe_random_generator::get_range (uint32_t r_max)
69{
70 return next () % r_max;
71}
72
73// return a number within (min .. max)
74int
75tausworthe_random_generator::get_range (int r_min, int r_max)
76{
77 return r_min + (*this) (max (r_max - r_min + 1, 1));
64} 78}
65 79
66/* 80/*
67 * The random functions here take luck into account when rolling random 81 * The random functions here take luck into account when rolling random
68 * dice or numbers. This function has less of an impact the larger the 82 * dice or numbers. This function has less of an impact the larger the

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines