Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #if !defined AMX_NORANDOM
- /* This routine comes from the book "Inner Loops" by Rick Booth, Addison-Wesley
- * (ISBN 0-201-47960-5). This is a "multiplicative congruential random number
- * generator" that has been extended to 31-bits (the standard C version returns
- * only 15-bits).
- */
- #define INITIAL_SEED 0xcaa938dbL
- static unsigned long IL_StandardRandom_seed = INITIAL_SEED; /* always use a non-zero seed */
- #define IL_RMULT 1103515245L
- #if defined __BORLANDC__ || defined __WATCOMC__
- #pragma argsused
- #endif
- static cell AMX_NATIVE_CALL core_random(AMX *amx,const cell *params)
- {
- unsigned long lo, hi, ll, lh, hh, hl;
- unsigned long result;
- /* one-time initialization (or, mostly one-time) */
- #if !defined SN_TARGET_PS2 && !defined _WIN32_WCE && !defined __ICC430__
- if (IL_StandardRandom_seed == INITIAL_SEED)
- IL_StandardRandom_seed=(unsigned long)time(NULL);
- #endif
- (void)amx;
- lo = IL_StandardRandom_seed & 0xffff;
- hi = IL_StandardRandom_seed >> 16;
- IL_StandardRandom_seed = IL_StandardRandom_seed * IL_RMULT + 12345;
- ll = lo * (IL_RMULT & 0xffff);
- lh = lo * (IL_RMULT >> 16 );
- hl = hi * (IL_RMULT & 0xffff);
- hh = hi * (IL_RMULT >> 16 );
- result = ((ll + 12345) >> 16) + lh + hl + (hh << 16);
- result &= ~LONG_MIN; /* remove sign bit */
- if (params[1]!=0)
- result %= params[1];
- return (cell)result;
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement