home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / dev / gcc / libnixV0_8.lha / gnu / libnix-sources.lha / sources / amiga / misc / RangeRand.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-12  |  314 b   |  19 lines

  1. #include <exec/types.h>
  2.  
  3. ULONG RangeSeed;
  4.  
  5. ULONG RangeRand(ULONG maxValue)
  6. { ULONG a=RangeSeed;
  7.   UWORD i=maxValue-1;
  8.   do
  9.   { ULONG b=a;
  10.     a<<=1;
  11.     if((LONG)b<=0)
  12.       a^=0x1d872b41;
  13.   }while(i>>=1);
  14.   RangeSeed=a;
  15.   if((UWORD)maxValue)
  16.     return (UWORD)((UWORD)a*(UWORD)maxValue>>16);
  17.   return (UWORD)a;
  18. }
  19.