home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / c / hce.lha / HCE / LibSource / clib / Misc / src / rand.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-02  |  328 b   |  19 lines

  1. /*
  2.  *    In environments where the operating system doesn't provide
  3.  *    a random number generator, the following code may be useful.
  4.  */
  5.  
  6. static unsigned long _seed = 1;
  7.  
  8. int rand()
  9. {
  10.     _seed = (_seed * 1103515245) + 12345;
  11.     return((unsigned int) ((_seed / 65536) % 32768));
  12. }
  13.  
  14. void srand(seed)
  15. unsigned int seed;
  16. {
  17.     _seed = seed;
  18. }
  19.