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 int valid_range( ) 00017 { 00018 std::ofstream output("testBug73093.cout"); 00019 00020 int bad = 0; 00021 long seed; 00022 long mult=-235421; 00023 // use several seeds 00024 for( int il=0; il<100; ++il ) { 00025 if( sizeof(long) > 4 ) { 00026 // using atol so 32bit compilers won't complain 00027 seed = atol("9899876543210000"); 00028 mult = mult + atol("120034020050070"); 00029 } else { 00030 seed = 987654321; 00031 mult = mult + 12003400; 00032 } 00033 seed += il*mult; 00034 00035 CLHEP::Ranlux64Engine rng; 00036 const long N = 20; 00037 00038 rng.setSeed(seed, /*lux*/ 1); 00039 output << std::endl; 00040 output << "sizeof(long) = " << sizeof(long) << std::endl; 00041 output << "Generating " << N << " random numbers with seed " << seed << std::endl; 00042 output << "Using seed " << seed << std::endl; 00043 00044 double sum(0); 00045 for (long i=0; i<N; ++i) { 00046 double r = rng.flat(); 00047 if( std::abs(r) > 1.0 ) ++bad; 00048 output << r << std::endl; 00049 sum += r; 00050 } 00051 00052 output << "Sum: " << sum << std::endl; 00053 output << "Average: " << sum / N << std::endl; 00054 } 00055 00056 return bad; 00057 } 00058 00059 int check_sequence() 00060 { 00061 // if the seed is less than 32bits long on a 64bit machine, the random 00062 // number sequence should be the same as the sequence on a 32bit machine 00063 std::ofstream output("testBug73093.seq"); 00064 int bad = 0; 00065 long seed; 00066 long mult=-235421; 00067 // use several seeds 00068 for( int il=0; il<50; ++il ) { 00069 seed = 97654321; 00070 seed += il*mult; 00071 00072 CLHEP::Ranlux64Engine rng; 00073 const long N = 20; 00074 00075 rng.setSeed(seed, /*lux*/ 1); 00076 00077 double sum(0); 00078 for (long i=0; i<N; ++i) { 00079 double r = rng.flat(); 00080 if( std::abs(r) > 1.0 ) ++bad; 00081 output << "[" << il << "][" << i << "] = " << r << ";" << std::endl; 00082 sum += r; 00083 } 00084 } 00085 return bad; 00086 } 00087 00088 int main() 00089 { 00090 00091 int bad = 0; 00092 bad += valid_range( ); 00093 bad += check_sequence( ); 00094 00095 return bad; 00096 }