CLHEP VERSION Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 // ---------------------------------------------------------------------- 00002 // 00003 // testBug73093 -- Test of CLHEP::Ranlux64Engine with 64 bit seeds 00004 // 00005 // Frank Winklmeier 2010-09-24 00006 // L. Garren 2010-10-21 rewritten for test suite 00007 // 00008 // ---------------------------------------------------------------------- 00009 00010 #include <iostream> 00011 #include <cmath> 00012 #include <stdlib.h> 00013 00014 #include "CLHEP/Random/Ranlux64Engine.h" 00015 00016 using namespace std; 00017 00018 int valid_range( ) 00019 { 00020 std::ofstream output("testBug73093.cout"); 00021 00022 int bad = 0; 00023 long seed; 00024 long mult=-235421; 00025 // use several seeds 00026 for( int il=0; il<100; ++il ) { 00027 if( sizeof(long) > 4 ) { 00028 // using atol so 32bit compilers won't complain 00029 seed = atol("9899876543210000"); 00030 mult = mult + atol("120034020050070"); 00031 } else { 00032 seed = 987654321; 00033 mult = mult + 12003400; 00034 } 00035 seed += il*mult; 00036 00037 CLHEP::Ranlux64Engine rng; 00038 const long N = 20; 00039 00040 rng.setSeed(seed, /*lux*/ 1); 00041 output << endl; 00042 output << "sizeof(long) = " << sizeof(long) << endl; 00043 output << "Generating " << N << " random numbers with seed " << seed << endl; 00044 output << "Using seed " << seed << endl; 00045 00046 double sum(0); 00047 for (long i=0; i<N; ++i) { 00048 double r = rng.flat(); 00049 if( abs(r) > 1.0 ) ++bad; 00050 output << r << endl; 00051 sum += r; 00052 } 00053 00054 output << "Sum: " << sum << endl; 00055 output << "Average: " << sum / N << endl; 00056 } 00057 00058 return bad; 00059 } 00060 00061 int check_sequence() 00062 { 00063 // if the seed is less than 32bits long on a 64bit machine, the random 00064 // number sequence should be the same as the sequence on a 32bit machine 00065 std::ofstream output("testBug73093.seq"); 00066 int bad = 0; 00067 long seed; 00068 long mult=-235421; 00069 // use several seeds 00070 for( int il=0; il<50; ++il ) { 00071 seed = 97654321; 00072 seed += il*mult; 00073 00074 CLHEP::Ranlux64Engine rng; 00075 const long N = 20; 00076 00077 rng.setSeed(seed, /*lux*/ 1); 00078 00079 double sum(0); 00080 for (long i=0; i<N; ++i) { 00081 double r = rng.flat(); 00082 if( abs(r) > 1.0 ) ++bad; 00083 output << "[" << il << "][" << i << "] = " << r << ";" << endl; 00084 sum += r; 00085 } 00086 } 00087 return bad; 00088 } 00089 00090 int main() 00091 { 00092 00093 int bad = 0; 00094 bad += valid_range( ); 00095 bad += check_sequence( ); 00096 00097 return bad; 00098 }