00001 /* A C-program for MT19937: Real number version([0,1)-interval) */ 00002 /* (1999/10/28) */ 00003 /* genrand() generates one pseudorandom real number (double) */ 00004 /* which is uniformly distributed on [0,1)-interval, for each */ 00005 /* call. sgenrand(seed) sets initial values to the working area */ 00006 /* of 624 words. Before genrand(), sgenrand(seed) must be */ 00007 /* called once. (seed is any 32-bit integer.) */ 00008 /* Integer generator is obtained by modifying two lines. */ 00009 /* Coded by Takuji Nishimura, considering the suggestions by */ 00010 /* Topher Cooper and Marc Rieffel in July-Aug. 1997. */ 00011 00012 /* This library is free software; you can redistribute it and/or */ 00013 /* modify it under the terms of the GNU Library General Public */ 00014 /* License as published by the Free Software Foundation; either */ 00015 /* version 2 of the License, or (at your option) any later */ 00016 /* version. */ 00017 /* This library is distributed in the hope that it will be useful, */ 00018 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 00019 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ 00020 /* See the GNU Library General Public License for more details. */ 00021 /* You should have received a copy of the GNU Library General */ 00022 /* Public License along with this library; if not, write to the */ 00023 /* Free Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA */ 00024 /* 02111-1307 USA */ 00025 00026 /* Copyright (C) 1997, 1999 Makoto Matsumoto and Takuji Nishimura. */ 00027 /* Any feedback is very welcome. For any question, comments, */ 00028 /* see http://www.math.keio.ac.jp/matumoto/emt.html or email */ 00029 /* matumoto@math.keio.ac.jp */ 00030 00031 /* REFERENCE */ 00032 /* M. Matsumoto and T. Nishimura, */ 00033 /* "Mersenne Twister: A 623-Dimensionally Equidistributed Uniform */ 00034 /* Pseudo-Random Number Generator", */ 00035 /* ACM Transactions on Modeling and Computer Simulation, */ 00036 /* Vol. 8, No. 1, January 1998, pp 3--30. */ 00037 00038 00039 /* Adapted by Martin Reinsprecht and Raphael Langerhorst */ 00040 /* for the G System */ 00041 00042 #ifndef UTILPSEUDORNGH 00043 #define UTILPSEUDORNGH 00044 00045 namespace GBE 00046 { 00047 00048 namespace Util 00049 { 00050 00051 /* Period parameters */ 00052 #define N 624 00053 #define M 397 00054 #define MATRIX_A 0x9908b0df /* constant vector a */ 00055 #define UPPER_MASK 0x80000000 /* most significant w-r bits */ 00056 #define LOWER_MASK 0x7fffffff /* least significant r bits */ 00057 00058 /* Tempering parameters */ 00059 #define TEMPERING_MASK_B 0x9d2c5680 00060 #define TEMPERING_MASK_C 0xefc60000 00061 #define TEMPERING_SHIFT_U(y) (y >> 11) 00062 #define TEMPERING_SHIFT_S(y) (y << 7) 00063 #define TEMPERING_SHIFT_T(y) (y << 15) 00064 #define TEMPERING_SHIFT_L(y) (y >> 18) 00065 00066 static unsigned long mt[ N ]; /* the array for the state vector */ 00067 static int mti = N + 1; /* mti==N+1 means mt[N] is not initialized */ 00068 class PseudoRNG 00069 { 00070 00071 public: 00072 // Standard Constructor 00073 PseudoRNG(); 00074 // Standard Destruktor 00075 ~PseudoRNG(); 00076 int i; 00077 double getNumberDouble( void ); 00078 unsigned long getNumberInt( void ); 00079 void setNumber( unsigned long ); 00080 private: 00081 void sgenrand( unsigned long seed ); 00082 void lsgenrand( unsigned long seed_array[] ); 00083 double genrandDouble(); 00084 unsigned long genrandInt(); 00085 //double genrand(unsigned long y, unsigned long mag01[2]); 00086 }; 00087 } //Util namespace 00088 } //GBE namespace 00089 00090 #endif
1.3.6