CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

randomgen.h

00001 /*
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 __CS_RNG_H__
00024 #define __CS_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:
00046   csRandomGen ()
00047   { Initialize (); }
00049   csRandomGen (uint32 iSeed)
00050   { Initialize (iSeed); }
00051 
00053   void Initialize ();
00055   void Initialize (uint32 iSeed);
00056 
00058   float Get ()
00059   { return RANMAR (); }
00061   uint32 Get (uint32 iLimit);
00062 
00064   bool SelfTest ();
00065 
00066 private:
00068   void InitRANMAR (uint32 ij, uint32 kl);
00070   float RANMAR ();
00071 };
00072 
00073 #endif // __CS_RNG_H__

Generated for Crystal Space by doxygen 1.2.14