Debian Codegraph @

src/ITGSend/newran/geturng.cpp

raw symbols SCIP
1 /// \ingroup newran
2 ///@{
3
4 /// \file geturng.cpp
5 /// Get binary data from uniform generators for further testing.
6
7 #define WANT_STREAM
8 #define WANT_FSTREAM
9
10 #include "include.h"
11 #include "newran.h"
12
13
14
15 #ifdef use_namespace
16 using namespace NEWRAN;
17 #endif
18
19 int main()
20 {
21
22 Real* s1; Real* s2; Real* s3; Real* s4;
23 cout << "\nBegin test\n"; // Forces cout to allocate memory at beginning
24 cout << "Now print a real number: " << 3.14159265 << endl;
25 { s1 = new Real[8000]; delete [] s1; }
26 { s3 = new Real; delete s3;}
27
28
29 Try
30 {
31 bool copy_seed_from_disk = false;
32
33 double N = 2500000;
34
35 bool Bytes = true; // we take the top byte only
36 //bool Bytes = false; // we take the whole word
37
38 cout << endl;
39
40 Random::SetDirectory("c:\\seed\\");
41
42
43 {
44
45 LGM_mixed urng;
46 //LGM_simple urng;
47 //FM urng;
48 //MT urng;
49 //MotherOfAll urng;
50 //MultWithCarry urng;
51 //WH urng;
52 cout << "Testing " << urng.Name() << ", N = " << N << ", ";
53 if (Bytes) cout << "top byte" << endl;
54 else cout << "whole word" << endl;
55 Random::Set(urng);
56 if (copy_seed_from_disk) Random::CopySeedFromDisk(true);
57
58 ofstream os("ran_nos.bin",ios::binary);
59 if (Bytes)
60 {
61 for (int i = 0; i < N * 4; ++i)
62 {
63 unsigned long x = urng.ulNext();
64 os.put((unsigned char)((x >> 24) & 0xFF));
65 }
66 }
67 else
68 {
69 for (int i = 0; i < N; ++i)
70 {
71 unsigned long x = urng.ulNext();
72 os.put((unsigned char)(x & 0xFF));
73 os.put((unsigned char)((x >> 8) & 0xFF));
74 os.put((unsigned char)((x >> 16) & 0xFF));
75 os.put((unsigned char)((x >> 24) & 0xFF));
76 }
77 }
78 os.close();
79
80 }
81
82 Random::SetDirectory("");
83 }
84 Catch(BaseException)
85 {
86 cout << "\nTest program fails - exception generated\n\n";
87 cout << BaseException::what() << "\n";
88 }
89 CatchAll
90 {
91 cout << "\nTest program fails - exception generated\n\n";
92 }
93
94
95
96
97 { s2 = new Real[8000]; delete [] s2; }
98 cout << "\n(The following memory checks are probably not valid with all\n";
99 cout << "compilers - see documentation)\n";
100 cout << "\nChecking for lost memory: "
101 << (unsigned long)s1 << " " << (unsigned long)s2 << " ";
102 if (s1 != s2) cout << " - error\n"; else cout << " - ok\n";
103 { s4 = new Real; delete s4;}
104 cout << "\nChecking for lost memory: "
105 << (unsigned long)s3 << " " << (unsigned long)s4 << " ";
106 if (s3 != s4) cout << " - error\n"; else cout << " - ok\n";
107 cout << endl;
108
109 return 0;
110 }
111
112
113 ///@}
114