X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Flib.c;h=2ce5c980a728c0990944932a75e3b0d3a52c3e59;hb=3e11c7767641614fbb3fad38fffefa0da9e66919;hp=cab15b3c758b363fec6af1dc2750e6c50007c112;hpb=da67fd4fd32d16dcd6b4cb0b63497a9925a2ef35;p=tpg%2Facess2.git diff --git a/Kernel/lib.c b/Kernel/lib.c index cab15b3c..2ce5c980 100644 --- a/Kernel/lib.c +++ b/Kernel/lib.c @@ -8,7 +8,7 @@ #define RANDOM_SEED 0xACE55052 #define RANDOM_A 0x00731ADE #define RANDOM_C 12345 -#define RANDOM_SPRUCE 0xf12b02b +#define RANDOM_SPRUCE 0xf12b039 // Jan Feb Mar Apr May Jun Jul Aug Sept Oct Nov Dec const short DAYS_BEFORE[] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; #define UNIX_TO_2K ((30*365*3600*24) + (7*3600*24)) //Normal years + leap years @@ -66,9 +66,6 @@ EXPORT(CheckMem); EXPORT(ModUtil_LookupString); EXPORT(ModUtil_SetIdent); -// === GLOBALS === -static Uint giRandomState = RANDOM_SEED; - // === CODE === /** * \brief Convert a string into an integer @@ -679,12 +676,27 @@ Sint64 timestamp(int sec, int mins, int hrs, int day, int month, int year) */ Uint rand(void) { - Uint old = giRandomState; + #if 0 + static Uint state = RANDOM_SEED; + Uint old = state; // Get the next state value - giRandomState = (RANDOM_A*giRandomState + RANDOM_C) & 0xFFFFFFFF; + giRandomState = (RANDOM_A*state + RANDOM_C); // Check if it has changed, and if it hasn't, change it - if(giRandomState == old) giRandomState += RANDOM_SPRUCE; - return giRandomState; + if(state == old) state += RANDOM_SPRUCE; + return state; + #else + // http://en.wikipedia.org/wiki/Xorshift + // 2010-10-03 + static Uint32 x = 123456789; + static Uint32 y = 362436069; + static Uint32 z = 521288629; + static Uint32 w = 88675123; + Uint32 t; + + t = x ^ (x << 11); + x = y; y = z; z = w; + return w = w ^ (w >> 19) ^ t ^ (t >> 8); + #endif } /* *