CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
testBug73093.cc
Go to the documentation of this file.
1// ----------------------------------------------------------------------
2//
3// testBug73093 -- Test of CLHEP::Ranlux64Engine with 64 bit seeds
4//
5// Frank Winklmeier 2010-09-24
6// L. Garren 2010-10-21 rewritten for test suite
7//
8// ----------------------------------------------------------------------
9
10#include <iostream>
11#include <cmath>
12#include <stdlib.h>
13
14#include "CLHEP/Random/Ranlux64Engine.h"
15
17{
18 std::ofstream output("testBug73093.cout");
19
20 int bad = 0;
21 long seed;
22 long mult=-235421;
23 // use several seeds
24 for( int il=0; il<100; ++il ) {
25 if( sizeof(long) > 4 ) {
26 // using atol so 32bit compilers won't complain
27 seed = atol("9899876543210000");
28 mult = mult + atol("120034020050070");
29 } else {
30 seed = 987654321;
31 mult = mult + 12003400;
32 }
33 seed += il*mult;
34
36 const long N = 20;
37
38 rng.setSeed(seed, /*lux*/ 1);
39 output << std::endl;
40 output << "sizeof(long) = " << sizeof(long) << std::endl;
41 output << "Generating " << N << " random numbers with seed " << seed << std::endl;
42 output << "Using seed " << seed << std::endl;
43
44 double sum(0);
45 for (long i=0; i<N; ++i) {
46 double r = rng.flat();
47 if( std::abs(r) > 1.0 ) ++bad;
48 output << r << std::endl;
49 sum += r;
50 }
51
52 output << "Sum: " << sum << std::endl;
53 output << "Average: " << sum / N << std::endl;
54 }
55
56 return bad;
57}
58
60{
61 // if the seed is less than 32bits long on a 64bit machine, the random
62 // number sequence should be the same as the sequence on a 32bit machine
63 std::ofstream output("testBug73093.seq");
64 int bad = 0;
65 long seed;
66 long mult=-235421;
67 // use several seeds
68 for( int il=0; il<50; ++il ) {
69 seed = 97654321;
70 seed += il*mult;
71
73 const long N = 20;
74
75 rng.setSeed(seed, /*lux*/ 1);
76
77 double __attribute__ ((unused)) sum = 0;
78 for (long i=0; i<N; ++i) {
79 double r = rng.flat();
80 if( std::abs(r) > 1.0 ) ++bad;
81 output << "[" << il << "][" << i << "] = " << r << ";" << std::endl;
82 sum += r;
83 }
84 }
85 return bad;
86}
87
88int main()
89{
90
91 int bad = 0;
92 bad += valid_range( );
93 bad += check_sequence( );
94
95 return bad;
96}
97
void setSeed(long seed, int lxr=1)
std::ofstream output("ranRestoreTest.cout")
int check_sequence()
Definition: testBug73093.cc:59
int valid_range()
Definition: testBug73093.cc:16
int main()
Definition: testBug73093.cc:88