32 const double m1 = 4294967087.0;
33 const double m2 = 4294944443.0;
34 const double norm = 1.0 / (m1 + 1.0);
35 const double a12 = 1403580.0;
36 const double a13n = 810728.0;
37 const double a21 = 527612.0;
38 const double a23n = 1370589.0;
40 const double two53 = 9007199254740992.0;
41 const double fact = 5.9604644775390625e-8;
44 { 184888585.0, 0.0, 1945170933.0 },
50 { 0.0, 360363334.0, 4225571728.0 },
58 { -810728.0, 1403580.0, 0.0 }
64 { -1370589.0, 0.0, 527612.0 }
71 double MultModM (
double a,
double s,
double c,
double m)
78 if (v >= two53 || v <= -two53)
80 a1 =
static_cast<int32_t
> (a /
two17);
83 a1 =
static_cast<int32_t
> (v / m);
85 v = v * two17 + a * s + c;
88 a1 =
static_cast<int32_t
> (v / m);
90 if ((v -= a1 * m) < 0.0)
111 for (i = 0; i < 3; ++i)
113 x[i] =
MultModM (A[i][0], s[0], 0.0, m);
114 x[i] =
MultModM (A[i][1], s[1], x[i], m);
115 x[i] =
MultModM (A[i][2], s[2], x[i], m);
117 for (i = 0; i < 3; ++i)
135 for (i = 0; i < 3; ++i)
137 for (j = 0; j < 3; ++j)
142 for (j = 0; j < 3; ++j)
147 for (i = 0; i < 3; ++i)
149 for (j = 0; j < 3; ++j)
165 for (i = 0; i < 3; ++i)
167 for (j = 0; j < 3; ++j)
169 dst[i][j] = src[i][j];
173 for (i = 0; i < e; i++)
183 void MatPowModM (
const double A[3][3],
double B[3][3],
double m, int32_t n)
189 for (i = 0; i < 3; ++i)
191 for (j = 0; j < 3; ++j)
197 for (j = 0; j < 3; ++j)
224 for (
int i = 0; i < 190; i++)
230 return precalculated;
235 for (
int i = 0; i < 3; i ++)
237 for (
int j = 0; j < 3; j++)
239 a1p[i][j] = constants.
a1[n-1][i][j];
240 a2p[i][j] = constants.
a2[n-1][i][j];
259 k =
static_cast<int32_t
> (p1 /
m1);
265 m_currentState[0] = m_currentState[1]; m_currentState[1] = m_currentState[2]; m_currentState[2] = p1;
268 p2 =
a21 * m_currentState[5] -
a23n * m_currentState[3];
269 k =
static_cast<int32_t
> (p2 /
m2);
275 m_currentState[3] = m_currentState[4]; m_currentState[4] = m_currentState[5]; m_currentState[5] = p2;
278 u = ((p1 > p2) ? (p1 - p2) *
norm : (p1 - p2 +
m1) *
norm);
285 if (seedNumber >=
m1 || seedNumber >=
m2 || seedNumber == 0)
289 for (
int i = 0; i < 6; ++i)
299 for (
int i = 0; i < 6; ++i)
309 for (
int i = 0; i < 64; i++)
312 int bit = (nth >> nbit) & 0x1;