X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Flib.c;h=3399d3d85ca7af8fb496117c03f09d7eb4c8e170;hb=71d97264ff059a530d86584f690a43831468dc69;hp=35805b5a6bf2f0b7fadaf83cd174f8e56ce5e5a7;hpb=d7801bfc828d3328ac9a0172db8a71b8f33c4a19;p=tpg%2Facess2.git diff --git a/Kernel/lib.c b/Kernel/lib.c index 35805b5a..3399d3d8 100644 --- a/Kernel/lib.c +++ b/Kernel/lib.c @@ -6,8 +6,9 @@ // === CONSTANTS === #define RANDOM_SEED 0xACE55052 -#define RANDOM_A 0x12231ADE -#define RANDOM_C 0x1BADBEEF +#define RANDOM_A 0x00731ADE +#define RANDOM_C 12345 +#define RANDOM_SPRUCE 0xf12b02b // 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 @@ -15,6 +16,9 @@ const short DAYS_BEFORE[] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 3 // === PROTOTYPES === int ReadUTF8(Uint8 *str, Uint32 *Val); +// === GLOBALS === +static Uint giRandomState = RANDOM_SEED; + // === CODE === static const char cUCDIGITS[] = "0123456789ABCDEF"; /** @@ -137,7 +141,8 @@ int strcmp(char *str1, char *str2) */ int strncmp(char *Str1, char *Str2, size_t num) { - while(num-- && *Str1 && *Str1 == *Str2) + if(num == 0) return 0; // TODO: Check what should officially happen here + while(--num && *Str1 && *Str1 == *Str2) Str1++, Str2++; return *Str1-*Str2; } @@ -315,17 +320,12 @@ Sint64 timestamp(int sec, int mins, int hrs, int day, int month, int year) */ Uint rand() { - #if 0 - static Uint randomState = RANDOM_SEED; - Uint ret = randomState; - int roll = randomState & 31; - randomState = (randomState << roll) | (randomState >> (32-roll)); - randomState ^= 0x9A3C5E78; - return ret; - #else - static Uint randomState = RANDOM_SEED; - return randomState = (RANDOM_A*randomState + RANDOM_C) & 0xFFFFFFFF; - #endif + Uint old = giRandomState; + // Get the next state value + giRandomState = (RANDOM_A*giRandomState + RANDOM_C) & 0xFFFFFFFF; + // Check if it has changed, and if it hasn't, change it + if(giRandomState == old) giRandomState += RANDOM_SPRUCE; + return giRandomState; } EXPORT(timestamp);