home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / compiler / alib / rangerand.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  901 b   |  65 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: rangerand.c,v 1.2 1997/01/27 00:16:37 ldp Exp $
  4.  
  5.     Desc:
  6.     Lang: english
  7. */
  8. #include <exec/types.h>
  9.  
  10. ULONG RangeSeed;
  11.  
  12. /*****************************************************************************
  13.  
  14.     NAME */
  15. #include <proto/alib.h>
  16.  
  17.     ULONG RangeRand (
  18.  
  19. /*  SYNOPSIS */
  20.     ULONG maxValue)
  21.  
  22. /*  FUNCTION
  23.  
  24.     INPUTS
  25.  
  26.     RESULT
  27.  
  28.     NOTES
  29.  
  30.     EXAMPLE
  31.  
  32.     BUGS
  33.  
  34.     SEE ALSO
  35.  
  36.     INTERNALS
  37.  
  38.     HISTORY
  39.     06.12.96 digulla Created after original from libnix
  40.  
  41. ******************************************************************************/
  42. {
  43.     ULONG a = RangeSeed;
  44.     UWORD i = maxValue - 1;
  45.  
  46.     do
  47.     {
  48.     ULONG b = a;
  49.  
  50.     a <<= 1;
  51.  
  52.     if ((LONG)b <= 0)
  53.         a ^= 0x1d872b41;
  54.  
  55.     } while ((i >>= 1));
  56.  
  57.     RangeSeed = a;
  58.  
  59.     if ((UWORD)maxValue)
  60.     return (UWORD)((UWORD)a * (UWORD)maxValue >> 16);
  61.  
  62.     return (UWORD)a;
  63. } /* RangeRand */
  64.  
  65.