39 const double m1 = 4294967087.0;
40 const double m2 = 4294944443.0;
41 const double norm = 1.0 / (m1 + 1.0);
42 const double a12 = 1403580.0;
43 const double a13n = 810728.0;
44 const double a21 = 527612.0;
45 const double a23n = 1370589.0;
47 const double two53 = 9007199254740992.0;
52 { -810728.0, 1403580.0, 0.0 }
58 { -1370589.0, 0.0, 527612.0 }
65 double MultModM (
double a,
double s,
double c,
double m)
72 if (v >= two53 || v <= -two53)
74 a1 =
static_cast<int32_t
> (a /
two17);
77 a1 =
static_cast<int32_t
> (v / m);
79 v = v * two17 + a * s + c;
82 a1 =
static_cast<int32_t
> (v / m);
84 if ((v -= a1 * m) < 0.0)
99 void MatVecModM (
const Matrix A,
const double s[3],
double v[3],
105 for (i = 0; i < 3; ++i)
107 x[i] =
MultModM (A[i][0], s[0], 0.0, m);
108 x[i] =
MultModM (A[i][1], s[1], x[i], m);
109 x[i] =
MultModM (A[i][2], s[2], x[i], m);
111 for (i = 0; i < 3; ++i)
129 for (i = 0; i < 3; ++i)
131 for (j = 0; j < 3; ++j)
136 for (j = 0; j < 3; ++j)
141 for (i = 0; i < 3; ++i)
143 for (j = 0; j < 3; ++j)
159 for (i = 0; i < 3; ++i)
161 for (j = 0; j < 3; ++j)
163 dst[i][j] = src[i][j];
167 for (i = 0; i < e; i++)
221 for (
int i = 0; i < 190; i++)
227 return precalculated;
232 for (
int i = 0; i < 3; i ++)
234 for (
int j = 0; j < 3; j++)
236 a1p[i][j] = constants.
a1[n-1][i][j];
237 a2p[i][j] = constants.
a2[n-1][i][j];
256 k =
static_cast<int32_t
> (p1 /
m1);
262 m_currentState[0] = m_currentState[1]; m_currentState[1] = m_currentState[2]; m_currentState[2] = p1;
265 p2 =
a21 * m_currentState[5] -
a23n * m_currentState[3];
266 k =
static_cast<int32_t
> (p2 /
m2);
272 m_currentState[3] = m_currentState[4]; m_currentState[4] = m_currentState[5]; m_currentState[5] = p2;
275 u = ((p1 > p2) ? (p1 - p2) *
norm : (p1 - p2 +
m1) *
norm);
282 if (seedNumber >=
m1 || seedNumber >=
m2 || seedNumber == 0)
286 for (
int i = 0; i < 6; ++i)
296 for (
int i = 0; i < 6; ++i)
306 for (
int i = 0; i < 64; i++)
309 int bit = (nth >> nbit) & 0x1;
void MatTwoPowModM(const Matrix src, Matrix dst, double m, int32_t e)
void MatVecModM(const Matrix A, const double s[3], double v[3], double m)
#define NS_FATAL_ERROR(msg)
fatal error handling
double MultModM(double a, double s, double c, double m)
Combined Multiple-Recursive Generator MRG32k3a.
void AdvanceNthBy(uint64_t nth, int by, double state[6])
NS_LOG_COMPONENT_DEFINE("RngStream")
RngStream(uint32_t seed, uint64_t stream, uint64_t substream)
struct Precalculated PowerOfTwoConstants(void)
double RandU01(void)
Generate the next random number for this stream.
void PowerOfTwoMatrix(int n, Matrix a1p, Matrix a2p)
void MatMatModM(const Matrix A, const Matrix B, Matrix C, double m)