A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
MRG32k3a Namespace Reference

Namespace for MRG32k3a implementation details. More...

Classes

struct  Precalculated
 The transition matrices of the two MRG components (in matrix form), raised to all powers of 2 from 1 to 191. More...
 

Typedefs

typedef double Matrix[3][3]
 Type for 3x3 matrix of doubles.
 

Functions

void MatMatModM (const Matrix A, const Matrix B, Matrix C, double m)
 Compute the matrix C = A*B MOD m.
 
void MatPowModM (const double A[3][3], double B[3][3], double m, int32_t n)
 Compute the matrix B = (A^n Mod m); works even if A = B.
 
void MatTwoPowModM (const Matrix src, Matrix dst, double m, int32_t e)
 Compute the matrix B = (A^(2^e) Mod m); works also if A = B.
 
void MatVecModM (const Matrix A, const double s[3], double v[3], double m)
 Compute the vector v = A*s MOD m.
 
double MultModM (double a, double s, double c, double m)
 Return (a*s + c) MOD m; a, s, c and m must be < 2^35.
 
Precalculated PowerOfTwoConstants ()
 Compute the transition matrices of the two MRG components raised to all powers of 2 from 1 to 191.
 
void PowerOfTwoMatrix (int n, Matrix a1p, Matrix a2p)
 Get the transition matrices raised to a power of 2.
 

Variables

const double a12 = 1403580.0
 First component multiplier of n - 2 value.
 
const double a13n = 810728.0
 First component multiplier of n - 3 value.
 
const Matrix A1p0
 First component transition matrix.
 
const double a21 = 527612.0
 Second component multiplier of n - 1 value.
 
const double a23n = 1370589.0
 Second component multiplier of n - 3 value.
 
const Matrix A2p0
 Second component transition matrix.
 
const double m1 = 4294967087.0
 First component modulus, 232 - 209.
 
const double m2 = 4294944443.0
 Second component modulus, 232 - 22853.
 
const double norm = 1.0 / (m1 + 1.0)
 Normalization to obtain randoms on [0,1).
 
const double two17 = 131072.0
 Decomposition factor for computing a*s in less than 53 bits, 217
 
const double two53 = 9007199254740992.0
 IEEE-754 floating point precision, 253
 

Detailed Description

Namespace for MRG32k3a implementation details.

Typedef Documentation

◆ Matrix

typedef double MRG32k3a::Matrix[3][3]

Type for 3x3 matrix of doubles.

Definition at line 46 of file rng-stream.cc.

Function Documentation

◆ MatMatModM()

void MRG32k3a::MatMatModM ( const Matrix A,
const Matrix B,
Matrix C,
double m )

Compute the matrix C = A*B MOD m.

Assume that -m < s[i] < m. Note: works also if A = C or B = C or A = B = C.

Parameters
[in]AFirst matrix argument.
[in]BSecond matrix argument.
[out]CResult matrix.
[in]mModulus.

Definition at line 172 of file rng-stream.cc.

References MatVecModM().

Referenced by MatPowModM(), and MatTwoPowModM().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MatPowModM()

void MRG32k3a::MatPowModM ( const double A[3][3],
double B[3][3],
double m,
int32_t n )

Compute the matrix B = (A^n Mod m); works even if A = B.

Parameters
[in]AMatrix input argument.
[out]BMatrix output.
[in]mModulus.
[in]nExponent.

Definition at line 241 of file rng-stream.cc.

References MatMatModM().

+ Here is the call graph for this function:

◆ MatTwoPowModM()

void MRG32k3a::MatTwoPowModM ( const Matrix src,
Matrix dst,
double m,
int32_t e )

Compute the matrix B = (A^(2^e) Mod m); works also if A = B.

Parameters
[in]srcMatrix input argument A.
[out]dstMatrix output B.
[in]mModulus.
[in]eThe exponent.

Definition at line 211 of file rng-stream.cc.

References MatMatModM().

Referenced by PowerOfTwoConstants().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MatVecModM()

void MRG32k3a::MatVecModM ( const Matrix A,
const double s[3],
double v[3],
double m )

Compute the vector v = A*s MOD m.

Assume that -m < s[i] < m. Works also when v = s.

Parameters
[in]AMatrix argument, 3x3.
[in]sThree component input vector.
[out]vThree component output vector.
[in]mModulus.

Definition at line 143 of file rng-stream.cc.

References MultModM().

Referenced by ns3::RngStream::AdvanceNthBy(), and MatMatModM().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MultModM()

double MRG32k3a::MultModM ( double a,
double s,
double c,
double m )

Return (a*s + c) MOD m; a, s, c and m must be < 2^35.

This computes the result exactly, without exceeding the 53 bit precision of doubles.

Parameters
[in]aFirst multiplicative argument.
[in]sSecond multiplicative argument.
[in]cAdditive argument.
[in]mModulus.
Returns
(a*s +c) MOD m

Definition at line 103 of file rng-stream.cc.

References two17, and two53.

Referenced by MatVecModM().

+ Here is the caller graph for this function:

◆ PowerOfTwoConstants()

Precalculated MRG32k3a::PowerOfTwoConstants ( )

Compute the transition matrices of the two MRG components raised to all powers of 2 from 1 to 191.

Returns
The precalculated powers of the transition matrices.

Definition at line 289 of file rng-stream.cc.

References MRG32k3a::Precalculated::a1, A1p0, MRG32k3a::Precalculated::a2, A2p0, m1, m2, and MatTwoPowModM().

Referenced by PowerOfTwoMatrix().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PowerOfTwoMatrix()

void MRG32k3a::PowerOfTwoMatrix ( int n,
Matrix a1p,
Matrix a2p )

Get the transition matrices raised to a power of 2.

Parameters
[in]nThe power of 2.
[out]a1pThe first transition matrix power.
[out]a2pThe second transition matrix power.

Definition at line 307 of file rng-stream.cc.

References MRG32k3a::Precalculated::a1, MRG32k3a::Precalculated::a2, and PowerOfTwoConstants().

Referenced by ns3::RngStream::AdvanceNthBy().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ a12

const double MRG32k3a::a12 = 1403580.0

First component multiplier of n - 2 value.

Definition at line 58 of file rng-stream.cc.

Referenced by ns3::RngStream::RandU01().

◆ a13n

const double MRG32k3a::a13n = 810728.0

First component multiplier of n - 3 value.

Definition at line 61 of file rng-stream.cc.

Referenced by ns3::RngStream::RandU01().

◆ A1p0

const Matrix MRG32k3a::A1p0
Initial value:
= {
{ 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 },
{ -810728.0, 1403580.0, 0.0 }
}

First component transition matrix.

Definition at line 76 of file rng-stream.cc.

Referenced by PowerOfTwoConstants().

◆ a21

const double MRG32k3a::a21 = 527612.0

Second component multiplier of n - 1 value.

Definition at line 64 of file rng-stream.cc.

Referenced by ns3::RngStream::RandU01().

◆ a23n

const double MRG32k3a::a23n = 1370589.0

Second component multiplier of n - 3 value.

Definition at line 67 of file rng-stream.cc.

Referenced by ns3::RngStream::RandU01().

◆ A2p0

const Matrix MRG32k3a::A2p0
Initial value:
= {
{ 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 },
{ -1370589.0, 0.0, 527612.0 }
}

Second component transition matrix.

Definition at line 83 of file rng-stream.cc.

Referenced by PowerOfTwoConstants().

◆ m1

◆ m2

◆ norm

◆ two17

const double MRG32k3a::two17 = 131072.0

Decomposition factor for computing a*s in less than 53 bits, 217

Definition at line 70 of file rng-stream.cc.

Referenced by MultModM().

◆ two53

const double MRG32k3a::two53 = 9007199254740992.0

IEEE-754 floating point precision, 253

Definition at line 73 of file rng-stream.cc.

Referenced by MultModM().