CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
testBug73093.cc File Reference
#include <iostream>
#include <cmath>
#include <stdlib.h>
#include "CLHEP/Random/Ranlux64Engine.h"

Go to the source code of this file.

Functions

int valid_range ()
 
int check_sequence ()
 
int main ()
 

Function Documentation

◆ check_sequence()

int check_sequence ( )

Definition at line 59 of file testBug73093.cc.

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}
void setSeed(long seed, int lxr=1)
std::ofstream output("ranRestoreTest.cout")

Referenced by main().

◆ main()

int main ( )

Definition at line 88 of file testBug73093.cc.

89{
90
91 int bad = 0;
92 bad += valid_range( );
93 bad += check_sequence( );
94
95 return bad;
96}
int check_sequence()
Definition: testBug73093.cc:59
int valid_range()
Definition: testBug73093.cc:16

◆ valid_range()

int valid_range ( )

Definition at line 16 of file testBug73093.cc.

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}

Referenced by main().