Main Page   Class Hierarchy   Compound List   File List   Compound Members  

randomc.h

00001 /*
00002  *  This program is free software; you can redistribute it and/or modify
00003  *  it under the terms of the GNU General Public License as published by
00004  *  the Free Software Foundation; either version 2 of the License, or
00005  *  (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  * This file is extracted from the random generator library provided by Agner Fog
00017  * (http://www.agner.org/random/) and has been modified for Seagull.
00018  * (c) 2002 Agner Fog. GNU General Public License www.gnu.org/copyleft/gpl.html
00019  *
00020  * (c)Copyright 2006 Hewlett-Packard Development Company, LP.
00021  *
00022  */
00023 
00024 #ifndef RANDOMC_H
00025 #define RANDOMC_H
00026 
00027 #ifdef __INTEL_COMPILER
00028   #include <mathimf.h>       // Intel math function library
00029 #else
00030   #include <math.h>          // default math function linrary
00031 #endif
00032 
00033 #include <assert.h>
00034 #include <stdio.h>
00035 
00036 // Define 32 bit signed and unsigned integers.
00037 // Change these definitions, if necessary, on 64 bit computers
00038 typedef   signed long int32;
00039 typedef unsigned long uint32;
00040 
00041 class TRandomMersenne {                // encapsulate random number generator
00042   #if 0
00043     // define constants for MT11213A:
00044     // (32 bit constants cannot be defined as enum in 16-bit compilers)
00045     #define MERS_N   351
00046     #define MERS_M   175
00047     #define MERS_R   19
00048     #define MERS_U   11
00049     #define MERS_S   7
00050     #define MERS_T   15
00051     #define MERS_L   17
00052     #define MERS_A   0xE4BD75F5
00053     #define MERS_B   0x655E5280
00054     #define MERS_C   0xFFD58000
00055   #else
00056     // or constants for MT19937:
00057     #define MERS_N   624
00058     #define MERS_M   397
00059     #define MERS_R   31
00060     #define MERS_U   11
00061     #define MERS_S   7
00062     #define MERS_T   15
00063     #define MERS_L   18
00064     #define MERS_A   0x9908B0DF
00065     #define MERS_B   0x9D2C5680
00066     #define MERS_C   0xEFC60000
00067   #endif
00068   public:
00069   TRandomMersenne(uint32 seed) {       // constructor
00070     RandomInit(seed);}
00071   void RandomInit(uint32 seed);        // re-seed
00072   double Random();                     // output random float
00073   uint32 BRandom();                    // output random bits
00074   private:
00075   uint32 mt[MERS_N];                   // state vector
00076   int mti;                             // index into mt
00077   enum TArch {LITTLE_ENDIAN1, BIG_ENDIAN1, NONIEEE};
00078   TArch Architecture;                  // conversion to float depends on computer architecture
00079   };
00080 
00081 #endif

Generated on Wed Mar 7 14:44:59 2007 for Seagull by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002