home *** CD-ROM | disk | FTP | other *** search
/ Boldly Go Collection / version40.iso / TS / 17A / DRWIN101.ZIP / R250.HPP < prev    next >
C/C++ Source or Header  |  1991-05-30  |  1KB  |  41 lines

  1. #ifndef __R250_HPP
  2. #define __R250_HPP
  3.  
  4.  
  5. #define SIZE           250
  6. #define PREV           103
  7.  
  8. #ifndef WORD
  9.   typedef unsigned int WORD;
  10. #endif
  11. #ifndef DWORD
  12.   typedef unsigned long int DWORD;
  13. #endif
  14.  
  15.  
  16. class R250 {                           //pseudorandom number generator
  17. private:
  18.   int  index;                          //index of second array element
  19.   DWORD r[SIZE];                       //pointer to array
  20. public:
  21.   R250(void);                          //fill randomly lau time
  22.   R250(int seed);                      //seed for initialization
  23. //~R250();                             //destructor doesn't do anything
  24.   DWORD rnd(void);                     //returns random on [0,0xFFFFFFFF]
  25.   WORD rnd(WORD topval) {              //returns random on [0,topval-1]
  26.     if (topval>1)
  27.       return ((WORD)rnd()) % topval;
  28.     else
  29.       return ((WORD)rnd()) & 1;
  30.   };
  31.   double frnd(void) {                  //doublizer, random on [0.0,1.0]
  32.     return ((double)(DWORD)rnd())/((double)0xFFFFFFFFUL);
  33.   };
  34.   double frnd(double lo,double hi) {   //doublizer, random on [lo,hi]
  35.     return (hi-lo)*frnd()+lo;          //put it in range
  36.   };
  37. };   //class R250
  38.  
  39.  
  40. #endif
  41.