|
rng.h00001 /* 00002 This random number generator originally appeared in "Toward a Universal 00003 Random Number Generator" by George Marsaglia and Arif Zaman. 00004 Florida State University Report: FSU-SCRI-87-50 (1987) 00005 00006 It was later modified by F. James and published in "A Review of Pseudo- 00007 random Number Generators" 00008 00009 THIS IS THE BEST KNOWN RANDOM NUMBER GENERATOR AVAILABLE. 00010 (However, a newly discovered technique can yield 00011 a period of 10^600. But that is still in the development stage.) 00012 00013 It passes ALL of the tests for random number generators and has a period 00014 of 2^144, is completely portable (gives bit identical results on all 00015 machines with at least 24-bit mantissas in the floating point 00016 representation). 00017 00018 The algorithm is a combination of a Fibonacci sequence (with lags of 97 00019 and 33, and operation "subtraction plus one, modulo one") and an 00020 "arithmetic sequence" (using subtraction). 00021 */ 00022 00023 #ifndef __RNG_H__ 00024 #define __RNG_H__ 00025 00026 #include "cstypes.h" 00027 00038 class csRandomGen 00039 { 00040 int i97, j97; 00041 float u [98]; 00042 float c, cd, cm; 00043 00044 public: 00045 00047 csRandomGen () 00048 { Initialize (); } 00050 csRandomGen (unsigned iSeed) 00051 { Initialize (iSeed); } 00052 00054 void Initialize (); 00056 void Initialize (unsigned iSeed); 00057 00059 float Get () 00060 { return RANMAR (); } 00062 unsigned Get (unsigned iLimit); 00063 00065 bool SelfTest (); 00066 00067 private: 00068 // Initialize the random number generator 00069 void InitRANMAR (unsigned ij, unsigned kl); 00070 // Get the next random number in sequence 00071 float RANMAR (); 00072 }; 00073 00074 #endif // __RNG_H__ Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000 |