Advertisement
user12name

Untitled

May 27th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.43 KB | None | 0 0
  1. #if !defined AMX_NORANDOM
  2. /* This routine comes from the book "Inner Loops" by Rick Booth, Addison-Wesley
  3.  * (ISBN 0-201-47960-5). This is a "multiplicative congruential random number
  4.  * generator" that has been extended to 31-bits (the standard C version returns
  5.  * only 15-bits).
  6.  */
  7. #define INITIAL_SEED  0xcaa938dbL
  8. static unsigned long IL_StandardRandom_seed = INITIAL_SEED; /* always use a non-zero seed */
  9. #define IL_RMULT 1103515245L
  10. #if defined __BORLANDC__ || defined __WATCOMC__
  11.   #pragma argsused
  12. #endif
  13. static cell AMX_NATIVE_CALL core_random(AMX *amx,const cell *params)
  14. {
  15.     unsigned long lo, hi, ll, lh, hh, hl;
  16.     unsigned long result;
  17.  
  18.     /* one-time initialization (or, mostly one-time) */
  19.     #if !defined SN_TARGET_PS2 && !defined _WIN32_WCE && !defined __ICC430__
  20.         if (IL_StandardRandom_seed == INITIAL_SEED)
  21.             IL_StandardRandom_seed=(unsigned long)time(NULL);
  22.     #endif
  23.  
  24.     (void)amx;
  25.  
  26.     lo = IL_StandardRandom_seed & 0xffff;
  27.     hi = IL_StandardRandom_seed >> 16;
  28.     IL_StandardRandom_seed = IL_StandardRandom_seed * IL_RMULT + 12345;
  29.     ll = lo * (IL_RMULT  & 0xffff);
  30.     lh = lo * (IL_RMULT >> 16    );
  31.     hl = hi * (IL_RMULT  & 0xffff);
  32.     hh = hi * (IL_RMULT >> 16    );
  33.     result = ((ll + 12345) >> 16) + lh + hl + (hh << 16);
  34.     result &= ~LONG_MIN;        /* remove sign bit */
  35.     if (params[1]!=0)
  36.         result %= params[1];
  37.     return (cell)result;
  38. }
  39. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement