2 #include "PhotosRandom.h"
8 bool PhotosRandom::init =
false;
9 int PhotosRandom::iseed[2] = { 1802, 9373 };
10 int PhotosRandom::i97 = 96;
11 int PhotosRandom::j97 = 32;
12 double PhotosRandom::uran[97] = { 0.0 };
13 double PhotosRandom::cran = 362436.0 / 16777216.0;
14 const double PhotosRandom::cdran = 7654321.0 / 16777216.0;
15 const double PhotosRandom::cmran = 16777213.0 / 16777216.0;
17 void PhotosRandom::setSeed(
int s1,
int s2)
19 if (s1 < 0 || s1 > 31327)
Log::Fatal(
"PhotosRandom::setSeed(): Seed(1) out of range [0,31327]", 8);
20 if (s2 < 0 || s2 > 30080)
Log::Fatal(
"PhotosRandom::setSeed(): Seed(2) out of range [0,30080]", 9);
37 void PhotosRandom::initialize()
39 long IS1, IS2, IS3, IS4, IS5;
43 IS1 = (iseed[0] / 177) % 177 + 2;
44 IS2 = iseed[0] % 177 + 2;
45 IS3 = (iseed[1] / 169) % 178 + 1;
47 for (
int i = 0; i < 97; i++) {
50 for (
int j = 0; j < 24; j++) {
51 IS5 = (((IS1 * IS2) % 179) * IS3) % 179;
55 IS4 = (53 * IS4 + 1) % 169;
56 if ((IS4 * IS5) % 64 >= 32) S = S + T;
62 Log::Debug(0) <<
"PhotosRandom::inititalize(): seed: " << iseed[0] <<
", " << iseed[1] << std::endl;
81 double PhotosRandom::randomReal()
83 if (!init)
Log::Fatal(
"PhotosRandom::randomReal(): generator not initialized", 1);
86 ret = uran[i97] - uran[j97];
87 if (ret < 0.0) ret += 1.;
90 if (i97 < 0) i97 = 96;
92 if (j97 < 0) j97 = 96;
94 if (cran < 0.0) cran += cmran;
96 if (ret < 0.0) ret += 1.0;
static ostream & Debug(unsigned short int code=0, bool count=true)
Four logging entries.
static void Fatal(string text, unsigned short int code=0)
Terminates the program with added default message or 'text'.