Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

Random.h

Go to the documentation of this file.
00001 /* WARANTY NOTICE AND COPYRIGHT
00002 This program is free software; you can redistribute it and/or
00003 modify it under the terms of the GNU General Public License
00004 as published by the Free Software Foundation; either version 2
00005 of the License, or (at your option) any later version.
00006 
00007 This program is distributed in the hope that it will be useful,
00008 but WITHOUT ANY WARRANTY; without even the implied warranty of
00009 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010 GNU General Public License for more details.
00011 
00012 You should have received a copy of the GNU General Public License
00013 along with this program; if not, write to the Free Software
00014 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00015 
00016 Copyright (C) Michael J. Meyer
00017 
00018 matmjm@mindspring.com
00019 spyqqqdia@yahoo.com
00020 
00021 */
00022 
00023 #ifndef martingale_random_h    
00024 #define martingale_random_h
00025 
00026 #include "TypedefsMacros.h"
00027 
00028 
00029 // Constants used by the Mersenne Twister
00030 /* Period parameters */  
00031 #define MT_N 624
00032 #define MT_M 397
00033 #define MT_D 227               // MT_N-MT_M
00034 #define MATRIX_A 0x9908b0df    // constant vector a 
00035 #define UPPER_MASK 0x80000000  // most significant w-r bits 
00036 #define LOWER_MASK 0x7fffffff  // least significant r bits 
00037 
00038 /* Tempering parameters */   
00039 #define TEMPERING_MASK_B 0x9d2c5680
00040 #define TEMPERING_MASK_C 0xefc60000
00041 #define TEMPERING_SHIFT_U(y)  (y >> 11)
00042 #define TEMPERING_SHIFT_S(y)  (y << 7)
00043 #define TEMPERING_SHIFT_T(y)  (y << 15)
00044 #define TEMPERING_SHIFT_L(y)  (y >> 18)
00045 
00046 
00056 MTGL_BEGIN_NAMESPACE(Martingale)
00057 MTGL_BEGIN_NAMESPACE(Random)
00058 
00059 
00060 
00068 class MersenneTwister {
00069         
00070     unsigned long* mt;             // the array for the state vector 
00071     int mti;                       // mti==N+1 means mt[N] is not initialized 
00072         
00073     // mag01[x] = x * MATRIX_A  for x=0,1 
00074     static unsigned long mag01[2];
00075                 
00076 public : 
00077 
00080 MersenneTwister(unsigned long seed=4357);
00081 
00083 Real u01();
00084 
00085 }; // end MersenneTwister
00086 
00087 
00088 
00090 int sign();
00091 
00093 Real N(Real x);
00094         
00096 Real nInverse(Real x);
00097  
00099 Real U01();
00100 
00102 int Uint(int n);
00103    
00105 Real sTN();
00106    
00107 
00108 MTGL_END_NAMESPACE(Random)   
00109 MTGL_END_NAMESPACE(Martingale)
00110 
00111 
00112 /* A C-program for MT19937: Real number version((0,1)-interval) */
00113 /* (2001/9/28)                                                  */
00114 /*   genrand() generates one pseudorandom real number (double)  */
00115 /* which is uniformly distributed on (0,1)-interval, for each   */
00116 /* call. sgenrand(seed) sets initial values to the working area */
00117 /* of 624 words. Before genrand(), sgenrand(seed) must be       */
00118 /* called once. (seed is any 32-bit integer.)                   */
00119 /* Integer generator is obtained by modifying two lines.        */
00120 /*   Coded by Takuji Nishimura, considering the suggestions by  */
00121 /* Topher Cooper and Marc Rieffel in July-Aug. 1997.            */
00122 
00123 /* This library is free software; you can redistribute it and/or   */
00124 /* modify it under the terms of the GNU Library General Public     */
00125 /* License as published by the Free Software Foundation; either    */
00126 /* version 2 of the License, or (at your option) any later         */
00127 /* version.                                                        */
00128 /* This library is distributed in the hope that it will be useful, */
00129 /* but WITHOUT ANY WARRANTY; without even the implied warranty of  */
00130 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.            */
00131 /* See the GNU Library General Public License for more details.    */
00132 /* You should have received a copy of the GNU Library General      */
00133 /* Public License along with this library; if not, write to the    */
00134 /* Free Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA   */ 
00135 /* 02111-1307  USA                                                 */
00136 
00137 /* Copyright (C) 1997, 1999, 2001                                  */
00138 /*    Makoto Matsumoto and  Takuji Nishimura.                      */
00139 /*                                                                 */
00140 /* Any feedback is very welcome. For any question, comments,       */
00141 /* see http://www.math.keio.ac.jp/matumoto/emt.html or email       */
00142 /* matumoto@math.keio.ac.jp                                        */
00143 
00144 /* REFERENCE                                                       */
00145 /* M. Matsumoto and T. Nishimura,                                  */
00146 /* "Mersenne Twister: A 623-Dimensionally Equidistributed Uniform  */
00147 /* Pseudo-Random Number Generator",                                */
00148 /* ACM Transactions on Modeling and Computer Simulation,           */
00149 /* Vol. 8, No. 1, January 1998, pp 3--30.                          */
00150 
00151 
00152 #endif
00153  

Generated on Mon Sep 22 02:16:32 2003 for Libor-Library by doxygen1.3-rc3