CrystalSpace

Public API Reference

Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class 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 "csextern.h"
00027 #include "cstypes.h"
00028 
00039 class CS_CRYSTALSPACE_EXPORT csRandomGen
00040 {
00041   int i97, j97;
00042   float u [98];
00043   float c, cd, cm;
00044 
00045 public:
00047   csRandomGen ()
00048   { Initialize (); }
00050   csRandomGen (uint32 iSeed)
00051   { Initialize (iSeed); }
00052 
00054   void Initialize ();
00056   void Initialize (uint32 iSeed);
00057 
00059   float Get ()
00060   { return RANMAR (); }
00062   uint32 Get (uint32 iLimit);
00063 
00065   bool SelfTest ();
00066 
00067 private:
00069   void InitRANMAR (uint32 ij, uint32 kl);
00071   float RANMAR ();
00072 };
00073 
00074 #endif // __CS_RNG_H__

Generated for Crystal Space by doxygen 1.4.4