home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / SourceCode / Tutorial / Cookbook / 29.Dice / rand.c < prev   
Encoding:
C/C++ Source or Header  |  1993-01-18  |  317 b   |  18 lines

  1. #include <libc.h>
  2. #include <sys/time.h>
  3. #define MAXRND 2147483649
  4. #include <sys/time.h>
  5. extern long random();
  6. extern void srandom();
  7.  
  8. int getrand(int MaxVal)
  9. {
  10. struct timeval tp;
  11. struct timezone tzp;
  12.  
  13.     gettimeofday(&tp, &tzp);
  14.     srandom((int) tp.tv_usec );
  15.     return(MaxVal * ((float) random()/(float) MAXRND) + 1 );
  16. }
  17.  
  18.