00001 /***************************** RANDOMC.H *********************** 2001-10-24 AF * 00002 * 00003 * This file contains class declarations for the C++ library of uniform 00004 * random number generators. 00005 * 00006 * Overview of classes: 00007 * ==================== 00008 * 00009 * class TRanrotBGenerator: 00010 * Random number generator of type RANROT-B. 00011 * Source file ranrotb.cpp 00012 * 00013 * class TRanrotWGenerator: 00014 * Random number generator of type RANROT-W. 00015 * Source file ranrotw.cpp 00016 * 00017 * class TRandomMotherOfAll: 00018 * Random number generator of type Mother-of-All (Multiply with carry). 00019 * Source file mother.cpp 00020 * 00021 * class TRandomMersenne: 00022 * Random number generator of type Mersenne twister. 00023 * Source file mersenne.cpp 00024 * 00025 * class TRandomMotRot: 00026 * Combination of Mother-of-All and RANROT-W generators. 00027 * Source file ranmoro.cpp and motrot.asm. 00028 * Coded in assembly language for improved speed. 00029 * Must link in RANDOMAO.LIB or RANDOMAC.LIB. 00030 * 00031 * 00032 * Member functions (methods): 00033 * =========================== 00034 * 00035 * All these classes have identical member functions: 00036 * 00037 * Constructor(long int seed): 00038 * The seed can be any integer. Usually the time is used as seed. 00039 * Executing a program twice with the same seed will give the same sequence of 00040 * random numbers. A different seed will give a different sequence. 00041 * 00042 * double Random(); 00043 * Gives a floating point random number in the interval 0 <= x < 1. 00044 * The resolution is 32 bits in TRanrotBGenerator, TRandomMotherOfAll and 00045 * TRandomMersenne. 52 or 63 bits in TRanrotWGenerator. 63 bits in 00046 * TRandomMotRot. 00047 * 00048 * int IRandom(int min, int max); 00049 * Gives an integer random number in the interval min <= x <= max. 00050 * The resolution is the same as for Random(). 00051 * 00052 * unsigned long BRandom(); 00053 * Gives 32 random bits. 00054 * Only available in the classes TRanrotWGenerator and TRandomMersenne. 00055 * 00056 * 00057 * Example: 00058 * ======== 00059 * The file EX-RAN.CPP contains an example of how to generate random numbers. 00060 * 00061 * 00062 * Further documentation: 00063 * ====================== 00064 * The file randomc.htm contains further documentation on these random number 00065 * generators. 00066 * 00067 *******************************************************************************/ 00068 00069 #ifndef RANDOMC_H 00070 #define RANDOMC_H 00071 00072 #include "Mutex.h" 00073 00074 class TRanrotBGenerator { // encapsulate random number generator 00075 enum constants { // define parameters 00076 KK = 17, JJ = 10, R1 = 13, R2 = 9 00077 }; 00078 00079 public: 00080 TRanrotBGenerator(); // constructor 00081 TRanrotBGenerator(long int seed); // constructor 00082 void RandomInit(long int seed); // initialization 00083 int IRandom(int min, int max); // get integer random number in desired interval 00084 double Random(); // get floating point random number 00085 00086 protected: 00087 int p1, p2; // indexes into buffer 00088 unsigned long randbuffer[KK]; // history buffer 00089 #ifdef SELF_TEST 00090 unsigned long randbufcopy[KK*2]; // used for self-test 00091 #endif 00092 00093 private: 00094 Mutex m_mutex; 00095 }; 00096 00097 00098 00099 #endif