home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / compiler / clib / rand.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-09  |  1.2 KB  |  85 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: rand.c,v 1.2 1997/01/08 04:12:53 ldp Exp $
  4.  
  5.     Desc: ANSI C functions rand() and srand()
  6.     Lang: english
  7. */
  8.  
  9. static unsigned int a = 1;
  10.  
  11. /*****************************************************************************
  12.  
  13.     NAME */
  14. #include <stdlib.h>
  15.  
  16.     int rand (
  17.  
  18. /*  SYNOPSIS */
  19.     void)
  20.  
  21. /*  FUNCTION
  22.     A random number generator.
  23.  
  24.     INPUTS
  25.     None.
  26.  
  27.     RESULT
  28.     A pseudo-random integer between 0 and RAND_MAX.
  29.  
  30.     NOTES
  31.  
  32.     EXAMPLE
  33.  
  34.     BUGS
  35.  
  36.     SEE ALSO
  37.  
  38.     INTERNALS
  39.  
  40.     HISTORY
  41.  
  42. ******************************************************************************/
  43. {
  44.     return (a = a * 1103515245 + 12345) % RAND_MAX;
  45. } /* rand */
  46.  
  47.  
  48. /*****************************************************************************
  49.  
  50.     NAME */
  51.     #include <stdlib.h>
  52.  
  53.     void srand (
  54.  
  55. /*  SYNOPSIS */
  56.     unsigned int seed)
  57.  
  58. /*  FUNCTION
  59.     Set the starting value for the random number generator rand()
  60.  
  61.     INPUTS
  62.     seed - New start value
  63.  
  64.     RESULT
  65.     None.
  66.  
  67.     NOTES
  68.  
  69.     EXAMPLE
  70.  
  71.     BUGS
  72.  
  73.     SEE ALSO
  74.  
  75.     INTERNALS
  76.  
  77.     HISTORY
  78.  
  79. ******************************************************************************/
  80. {
  81.     a = seed;
  82. } /* srand */
  83.  
  84.  
  85.