#include <sys/time.h>#include <unistd.h>#include <stdio.h>#include <string.h>#include "rng.h"Include dependency graph for rng.cc:

Go to the source code of this file.
Compounds | |
| class | RNGClass |
Defines | |
| #define | N_SEEDS_ 64 |
Functions | |
| double | MultModM (double a, double s, double c, double m) |
| void | MatVecModM (const double A[3][3], const double s[3], double v[3], double m) |
| void | MatMatModM (const double A[3][3], const double B[3][3], double C[3][3], double m) |
| void | MatTwoPowModM (const double A[3][3], double B[3][3], double m, long e) |
| void | MatPowModM (const double A[3][3], double B[3][3], double m, long n) |
| int | CheckSeed (const unsigned long seed[6]) |
Variables | |
| const char | rcsid [] |
| RNGClass | class_rng |
| const double | m1 = 4294967087.0 |
| const double | m2 = 4294944443.0 |
| const double | norm = 1.0 / (m1 + 1.0) |
| const double | a12 = 1403580.0 |
| const double | a13n = 810728.0 |
| const double | a21 = 527612.0 |
| const double | a23n = 1370589.0 |
| const double | two17 = 131072.0 |
| const double | two53 = 9007199254740992.0 |
| const double | fact = 5.9604644775390625e-8 |
| const double | InvA1 [3][3] |
| const double | InvA2 [3][3] |
| const double | A1p0 [3][3] |
| const double | A2p0 [3][3] |
| const double | A1p76 [3][3] |
| const double | A2p76 [3][3] |
| const double | A1p127 [3][3] |
| const double | A2p127 [3][3] |
|
|
|
|
|
Definition at line 658 of file rng.cc. Referenced by RNG::set_package_seed(), and RNG::set_seed().
00659 {
00660 int i;
00661 for (i = 0; i < 3; ++i) {
00662 if (seed[i] >= m1) {
00663 fprintf (stderr, "****************************************\n\n");
00664 fprintf (stderr, "ERROR: Seed[%d] >= 4294967087, Seed is not set.", i);
00665 fprintf (stderr, "\n\n****************************************\n\n");
00666 return (-1);
00667 }
00668 }
00669 for (i = 3; i < 6; ++i) {
00670 if (seed[i] >= m2) {
00671 fprintf (stderr, "****************************************\n\n");
00672 fprintf (stderr, "ERROR: Seed[%d] >= 429444443, Seed is not set.", i);
00673 fprintf (stderr, "\n\n****************************************\n\n");
00674 return (-1);
00675 }
00676 }
00677 if (seed[0] == 0 && seed[1] == 0 && seed[2] == 0) {
00678 fprintf (stderr, "****************************************\n\n");
00679 fprintf (stderr, "ERROR: First 3 seeds = 0.\n\n");
00680 fprintf (stderr, "****************************************\n\n");
00681 return (-1);
00682 }
00683 if (seed[3] == 0 && seed[4] == 0 && seed[5] == 0) {
00684 fprintf (stderr, "****************************************\n\n");
00685 fprintf (stderr, "ERROR: Last 3 seeds = 0.\n\n");
00686 fprintf (stderr, "****************************************\n\n");
00687 return (-1);
00688 }
00689 return 0;
00690 }
|
|
||||||||||||||||||||
|
Definition at line 593 of file rng.cc. References MatVecModM(). Referenced by RNG::advance_state(), MatPowModM(), and MatTwoPowModM().
00595 {
00596 int i, j;
00597 double V[3], W[3][3];
00598 for (i = 0; i < 3; ++i) {
00599 for (j = 0; j < 3; ++j)
00600 V[j] = B[j][i];
00601 MatVecModM (A, V, V, m);
00602 for (j = 0; j < 3; ++j)
00603
00604 W[j][i] = V[j];
00605 }
00606 for (i = 0; i < 3; ++i)
00607 for (j = 0; j < 3; ++j)
00608 C[i][j] = W[i][j];
00609 }
|
Here is the call graph for this function:

|
||||||||||||||||||||
|
Definition at line 632 of file rng.cc. References MatMatModM(). Referenced by RNG::advance_state().
00634 {
00635 int i, j;
00636 double W[3][3];
00637 /* initialize: W = A; B = I */
00638 for (i = 0; i < 3; ++i)
00639 for (j = 0; j < 3; ++j) {
00640 W[i][j] = A[i][j];
00641 B[i][j] = 0.0;
00642 }
00643 for (j = 0; j < 3; ++j)
00644 B[j][j] = 1.0;
00645 /* Compute B = A^n mod m using the binary decomposition of n */
00646 while (n > 0) {
00647 if (n % 2) MatMatModM (W, B, B, m);
00648 MatMatModM (W, W, W, m);
00649
00650 n/=2;
00651 }
00652 }
|
Here is the call graph for this function:

|
||||||||||||||||||||
|
Definition at line 614 of file rng.cc. References MatMatModM(). Referenced by RNG::advance_state().
00616 {
00617 int i, j;
00618 /* initialize: B = A */
00619 if (A != B) {
00620 for (i = 0; i < 3; ++i)
00621 for (j = 0; j < 3; ++j)
00622 B[i][j] = A[i][j];
00623 }
00624 /* Compute B = A^(2^e) mod m */
00625 for (i = 0; i < e; i++)
00626 MatMatModM (B, B, B, m);
00627 }
|
Here is the call graph for this function:

|
||||||||||||||||||||
|
Definition at line 575 of file rng.cc. References MultModM(). Referenced by RNG::advance_state(), RNG::init(), MatMatModM(), and RNG::reset_next_substream().
00577 {
00578 int i;
00579 double x[3]; // Necessary if v = s
00580 for (i = 0; i < 3; ++i) {
00581 x[i] = MultModM (A[i][0], s[0], 0.0, m);
00582 x[i] = MultModM (A[i][1], s[1], x[i], m);
00583 x[i] = MultModM (A[i][2], s[2], x[i], m);
00584 }
00585 for (i = 0; i < 3; ++i)
00586 v[i] = x[i];
00587 }
|
Here is the call graph for this function:

|
||||||||||||||||||||
|
Definition at line 554 of file rng.cc. Referenced by MatVecModM().
00555 {
00556 double v;
00557 long a1;
00558 v=a*s+c;
00559
00560 if (v >= two53 || v <= -two53) {
00561 a1 = static_cast<long> (a / two17); a -= a1 * two17;
00562 v =a1*s;
00563 a1 = static_cast<long> (v / m); v -= a1 * m;
00564 v = v * two17 + a * s + c;
00565 }
00566 a1 = static_cast<long> (v / m);
00567 /* in case v < 0)*/
00568 if ((v -= a1 * m) < 0.0) return v += m; else return v;
00569 }
|
|
|
Definition at line 490 of file rng.cc. Referenced by RNG::U01(). |
|
|
Definition at line 491 of file rng.cc. Referenced by RNG::U01(). |
|
|
Initial value: {
{ 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 },
{ -810728.0, 1403580.0, 0.0 }
}
Definition at line 514 of file rng.cc. Referenced by RNG::advance_state(). |
|
|
Initial value: {
{ 2427906178.0, 3580155704.0, 949770784.0 },
{ 226153695.0, 1230515664.0, 3580155704.0 },
{ 1988835001.0, 986791581.0, 1230515664.0 }
}
Definition at line 538 of file rng.cc. Referenced by RNG::init(). |
|
|
Initial value: {
{ 82758667.0, 1871391091.0, 4127413238.0 },
{ 3672831523.0, 69195019.0, 1871391091.0 },
{ 3672091415.0, 3528743235.0, 69195019.0 }
}
Definition at line 526 of file rng.cc. Referenced by RNG::reset_next_substream(). |
|
|
Definition at line 492 of file rng.cc. Referenced by RNG::U01(). |
|
|
Definition at line 493 of file rng.cc. Referenced by RNG::U01(). |
|
|
Initial value: {
{ 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 },
{ -1370589.0, 0.0, 527612.0 }
}
Definition at line 520 of file rng.cc. Referenced by RNG::advance_state(). |
|
|
Initial value: {
{ 1464411153.0, 277697599.0, 1610723613.0 },
{ 32183930.0, 1464411153.0, 1022607788.0 },
{ 2824425944.0, 32183930.0, 2093834863.0 }
}
Definition at line 544 of file rng.cc. Referenced by RNG::init(). |
|
|
Initial value: {
{ 1511326704.0, 3759209742.0, 1610795712.0 },
{ 4292754251.0, 1511326704.0, 3889917532.0 },
{ 3859662829.0, 4292754251.0, 3708466080.0 }
}
Definition at line 532 of file rng.cc. Referenced by RNG::reset_next_substream(). |
|
|
|
|
|
Definition at line 496 of file rng.cc. Referenced by RNG::U01d(). |
|
|
Initial value: {
{ 184888585.0, 0.0, 1945170933.0 },
{ 1.0, 0.0, 0.0 },
{ 0.0, 1.0, 0.0 }
}
Definition at line 502 of file rng.cc. Referenced by RNG::advance_state(). |
|
|
Initial value: {
{ 0.0, 360363334.0, 4225571728.0 },
{ 1.0, 0.0, 0.0 },
{ 0.0, 1.0, 0.0 }
}
Definition at line 508 of file rng.cc. Referenced by RNG::advance_state(). |
|
|
Definition at line 487 of file rng.cc. Referenced by RNG::advance_state(), CheckSeed(), RNG::init(), RNG::reset_next_substream(), and RNG::U01(). |
|
|
Definition at line 488 of file rng.cc. Referenced by RNG::advance_state(), CheckSeed(), RNG::init(), RNG::reset_next_substream(), and RNG::U01(). |
|
|
Definition at line 489 of file rng.cc. Referenced by RNG::U01(). |
|
|
Initial value:
"@(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/tools/rng.cc,v 1.27 2002/04/13 21:24:25 buchheim Exp $ (LBL)"
|
|
|
Definition at line 494 of file rng.cc. Referenced by MultModM(). |
|
|
Definition at line 495 of file rng.cc. Referenced by MultModM(). |
1.3.3