Random.hpp
Go to the documentation of this file.
00001 /**
00002  * \file Random.hpp
00003  * \brief Header for Random, RandomGenerator.
00004  *
00005  * This loads up the header for RandomCanonical, RandomEngine, etc., to
00006  * provide access to random integers of various sizes, random reals with
00007  * various precisions, a random probability, etc.
00008  *
00009  * Written by Charles Karney <charles@karney.com> and licensed under the LGPL.
00010  * For more information, see http://randomlib.sourceforge.net/
00011  **********************************************************************/
00012 
00013 #if !defined(RANDOM_HPP)
00014 #define RANDOM_HPP "$Id: Random.hpp 6723 2010-01-11 14:20:10Z ckarney $"
00015 
00016 
00017 #if defined(_MSC_VER)
00018 #define WINDOWS 1
00019 // Disable throw warnings
00020 #pragma warning (disable: 4290)
00021 #else
00022 #define WINDOWS 0
00023 #endif
00024 
00025 #if defined(__sparc)
00026 #define SUN 1
00027 #else
00028 #define SUN 0
00029 #endif
00030 
00031 #if WINDOWS
00032 typedef unsigned uint32_t;
00033 typedef unsigned long long uint64_t;
00034 #else
00035 #include <stdint.h>
00036 #endif
00037 /**
00038  * The type for 32-bit results
00039  **********************************************************************/
00040 #define RANDOM_U32_T uint32_t
00041 /**
00042  * The type for 44-bit results
00043  **********************************************************************/
00044 #define RANDOM_U64_T uint64_t
00045 
00046 #if defined(__GNUC__)
00047 // Suppress "defined but not used" warnings
00048 #define RCSID_DECL(x) namespace \
00049 { char VAR_ ## x [] __attribute__((unused)) = x; }
00050 #else
00051 /**
00052  * Insertion of RCS Id strings into the object file.
00053  **********************************************************************/
00054 #define RCSID_DECL(x) namespace { char VAR_ ## x [] = x; }
00055 #endif
00056 
00057 #if !defined(HAVE_SSE2)
00058 #define HAVE_SSE2 0
00059 #endif
00060 
00061 #if !defined(HAVE_ALTIVEC)
00062 // arch -> ppc
00063 // machine -> ppc970
00064 // uname -m -> Power Macintosh
00065 // uname -n -> biocvs1.sarnoff.com
00066 // uname -p -> powerpc
00067 // uname -s -> Darwin
00068 // uname -r -> 8.7.0
00069 // uname -v -> Darwin Kernel Version 8.7.0: Fri May 26 15:20:53 PDT 2006; root:xnu-792.6.76.obj~1/RELEASE_PPC
00070 #define HAVE_ALTIVEC 0
00071 #endif
00072 
00073 #if !defined(HAVE_BOOST_SERIALIZATION)
00074 /**
00075  * Use boost serialization?
00076  **********************************************************************/
00077 #define HAVE_BOOST_SERIALIZATION 0
00078 #endif
00079 
00080 #if !defined(RANDOM_LEGACY)
00081 /**
00082  * Instantiate legacy classes MixerMT0 and MixerMT1?
00083  **********************************************************************/
00084 #define RANDOM_LEGACY 0
00085 #endif
00086 
00087 /**
00088  * Use table, Power2::power2, for pow2?  This isn't necessary with g++ 4.0
00089  * because calls to std::pow are optimized.  g++ 4.1 seems to have lost
00090  * thiscapability though!
00091  **********************************************************************/
00092 #if defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ == 0
00093 #define RANDOM_POWERTABLE 0
00094 #else
00095 // otherwise use a lookup table
00096 #define RANDOM_POWERTABLE 1
00097 #endif
00098 
00099 #if WINDOWS
00100 #define RANDOM_LONGDOUBLEPREC 53
00101 #elif SUN
00102 #define RANDOM_LONGDOUBLEPREC 113
00103 #else
00104 /**
00105  * The precision of long doubles, used for sizing Power2::power2.  64 on
00106  * Linux/Intel, 106 on MaxOS/PowerPC
00107  **********************************************************************/
00108 #define RANDOM_LONGDOUBLEPREC __LDBL_MANT_DIG__
00109 #endif
00110 
00111 #if !defined(STATIC_ASSERT)
00112 #if defined(HAVE_STATIC_ASSERT)
00113 #define STATIC_ASSERT static_assert
00114 #else
00115 /**
00116  * A simple compile-time assert.
00117  **********************************************************************/
00118 #define STATIC_ASSERT(cond,reason) { enum{ STATIC_ASSERT_ENUM = 1/int(cond) }; }
00119 #endif
00120 #endif
00121 
00122 /**
00123  * Are denormalized reals of type RealType supported?
00124  **********************************************************************/
00125 #define RANDOM_HASDENORM(RealType) 1
00126 
00127 #include "RandomLib/RandomCanonical.hpp"
00128 
00129 namespace RandomLib {
00130 
00131 #if !defined(DEFAULT_GENERATOR)
00132 #define DEFAULT_GENERATOR SRandomGenerator32
00133 #endif
00134 
00135   /**
00136    * Point Random to one of a specific MT19937 generators.
00137    **********************************************************************/
00138 
00139   typedef DEFAULT_GENERATOR RandomGenerator;
00140 
00141   /**
00142    * Hook Random to RandomGenerator
00143    **********************************************************************/
00144   typedef RandomCanonical<RandomGenerator> Random;
00145 
00146 } // namespace RandomLib
00147 
00148 #endif  // RANDOM_HPP