src/core/rng-stream.cc
author Raj Bhattacharjea <raj.b@gatech.edu>
Thu, 22 Jan 2009 14:10:40 -0500
changeset 4224 40e5d5af3c71
parent 4222 509a818e8cdf
child 4231 6f9f859bae8b
permissions -rw-r--r--
Commit Mathieu's coding style cleanup of random-variable
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     2
//
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     3
//  Copyright (C) 2001  Pierre L'Ecuyer (lecuyer@iro.umontreal.ca)
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     4
//
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     5
// This program is free software; you can redistribute it and/or modify
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     6
// it under the terms of the GNU General Public License version 2 as
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     7
// published by the Free Software Foundation;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     8
//
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     9
// This program is distributed in the hope that it will be useful,
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    12
// GNU General Public License for more details.
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    13
//
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    14
// You should have received a copy of the GNU General Public License
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    15
// along with this program; if not, write to the Free Software
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    16
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    17
//
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    18
// Modified for ns-3 by: Rajib Bhattacharjea<raj.b@gatech.edu>
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    19
//
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    20
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    21
#include <cstdlib>
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    22
#include <iostream>
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    23
#include "rng-stream.h"
4221
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
    24
#include "global-value.h"
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
    25
#include "integer.h"
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    26
using namespace std;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    27
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    28
namespace
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    29
{
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    30
const double m1   =       4294967087.0;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    31
const double m2   =       4294944443.0;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    32
const double norm =       1.0 / (m1 + 1.0);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    33
const double a12  =       1403580.0;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    34
const double a13n =       810728.0;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    35
const double a21  =       527612.0;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    36
const double a23n =       1370589.0;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    37
const double two17 =      131072.0;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    38
const double two53 =      9007199254740992.0;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    39
const double fact =       5.9604644775390625e-8;     /* 1 / 2^24  */
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    40
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    41
// The following are the transition matrices of the two MRG components
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    42
// (in matrix form), raised to the powers -1, 1, 2^76, and 2^127, resp.
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    43
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    44
const double InvA1[3][3] = {          // Inverse of A1p0
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    45
       { 184888585.0,   0.0,  1945170933.0 },
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    46
       {         1.0,   0.0,           0.0 },
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    47
       {         0.0,   1.0,           0.0 }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    48
       };
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    49
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    50
const double InvA2[3][3] = {          // Inverse of A2p0
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    51
       {      0.0,  360363334.0,  4225571728.0 },
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    52
       {      1.0,          0.0,           0.0 },
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    53
       {      0.0,          1.0,           0.0 }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    54
       };
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    55
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    56
const double A1p0[3][3] = {
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    57
       {       0.0,        1.0,       0.0 },
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    58
       {       0.0,        0.0,       1.0 },
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    59
       { -810728.0,  1403580.0,       0.0 }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    60
       };
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    61
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    62
const double A2p0[3][3] = {
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    63
       {        0.0,        1.0,       0.0 },
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    64
       {        0.0,        0.0,       1.0 },
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    65
       { -1370589.0,        0.0,  527612.0 }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    66
       };
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    67
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    68
const double A1p76[3][3] = {
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    69
       {      82758667.0, 1871391091.0, 4127413238.0 },
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    70
       {    3672831523.0,   69195019.0, 1871391091.0 },
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    71
       {    3672091415.0, 3528743235.0,   69195019.0 }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    72
       };
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    73
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    74
const double A2p76[3][3] = {
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    75
       {    1511326704.0, 3759209742.0, 1610795712.0 },
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    76
       {    4292754251.0, 1511326704.0, 3889917532.0 },
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    77
       {    3859662829.0, 4292754251.0, 3708466080.0 }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    78
       };
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    79
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    80
const double A1p127[3][3] = {
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    81
       {    2427906178.0, 3580155704.0,  949770784.0 },
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    82
       {     226153695.0, 1230515664.0, 3580155704.0 },
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    83
       {    1988835001.0,  986791581.0, 1230515664.0 }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    84
       };
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    85
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    86
const double A2p127[3][3] = {
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    87
       {    1464411153.0,  277697599.0, 1610723613.0 },
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    88
       {      32183930.0, 1464411153.0, 1022607788.0 },
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    89
       {    2824425944.0,   32183930.0, 2093834863.0 }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    90
       };
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    91
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    92
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    93
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    94
//-------------------------------------------------------------------------
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    95
// Return (a*s + c) MOD m; a, s, c and m must be < 2^35
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    96
//
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    97
double MultModM (double a, double s, double c, double m)
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    98
{
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    99
    double v;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   100
    int32_t a1;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   101
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   102
    v = a * s + c;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   103
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   104
    if (v >= two53 || v <= -two53) {
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   105
        a1 = static_cast<int32_t> (a / two17);    a -= a1 * two17;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   106
        v  = a1 * s;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   107
        a1 = static_cast<int32_t> (v / m);     v -= a1 * m;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   108
        v = v * two17 + a * s + c;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   109
    }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   110
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   111
    a1 = static_cast<int32_t> (v / m);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   112
    /* in case v < 0)*/
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   113
    if ((v -= a1 * m) < 0.0) return v += m;   else return v;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   114
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   115
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   116
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   117
//-------------------------------------------------------------------------
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   118
// Compute the vector v = A*s MOD m. Assume that -m < s[i] < m.
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   119
// Works also when v = s.
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   120
//
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   121
void MatVecModM (const double A[3][3], const double s[3], double v[3],
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   122
                 double m)
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   123
{
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   124
    int i;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   125
    double x[3];               // Necessary if v = s
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   126
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   127
    for (i = 0; i < 3; ++i) {
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   128
        x[i] = MultModM (A[i][0], s[0], 0.0, m);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   129
        x[i] = MultModM (A[i][1], s[1], x[i], m);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   130
        x[i] = MultModM (A[i][2], s[2], x[i], m);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   131
    }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   132
    for (i = 0; i < 3; ++i)
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   133
        v[i] = x[i];
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   134
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   135
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   136
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   137
//-------------------------------------------------------------------------
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   138
// Compute the matrix C = A*B MOD m. Assume that -m < s[i] < m.
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   139
// Note: works also if A = C or B = C or A = B = C.
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   140
//
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   141
void MatMatModM (const double A[3][3], const double B[3][3],
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   142
                 double C[3][3], double m)
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   143
{
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   144
    int i, j;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   145
    double V[3], W[3][3];
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   146
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   147
    for (i = 0; i < 3; ++i) {
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   148
        for (j = 0; j < 3; ++j)
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   149
            V[j] = B[j][i];
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   150
        MatVecModM (A, V, V, m);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   151
        for (j = 0; j < 3; ++j)
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   152
            W[j][i] = V[j];
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   153
    }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   154
    for (i = 0; i < 3; ++i)
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   155
        for (j = 0; j < 3; ++j)
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   156
            C[i][j] = W[i][j];
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   157
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   158
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   159
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   160
//-------------------------------------------------------------------------
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   161
// Compute the matrix B = (A^(2^e) Mod m);  works also if A = B. 
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   162
//
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   163
void MatTwoPowModM (const double A[3][3], double B[3][3], double m, int32_t e)
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   164
{
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   165
   int i, j;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   166
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   167
   /* initialize: B = A */
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   168
   if (A != B) {
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   169
      for (i = 0; i < 3; ++i)
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   170
         for (j = 0; j < 3; ++j)
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   171
            B[i][j] = A[i][j];
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   172
   }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   173
   /* Compute B = A^(2^e) mod m */
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   174
   for (i = 0; i < e; i++)
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   175
      MatMatModM (B, B, B, m);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   176
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   177
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   178
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   179
//-------------------------------------------------------------------------
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   180
// Compute the matrix B = (A^n Mod m);  works even if A = B.
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   181
//
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   182
void MatPowModM (const double A[3][3], double B[3][3], double m, int32_t n)
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   183
{
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   184
    int i, j;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   185
    double W[3][3];
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   186
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   187
    /* initialize: W = A; B = I */
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   188
    for (i = 0; i < 3; ++i)
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   189
        for (j = 0; j < 3; ++j) {
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   190
            W[i][j] = A[i][j];
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   191
            B[i][j] = 0.0;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   192
        }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   193
    for (j = 0; j < 3; ++j)
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   194
        B[j][j] = 1.0;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   195
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   196
    /* Compute B = A^n mod m using the binary decomposition of n */
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   197
    while (n > 0) {
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   198
        if (n % 2) MatMatModM (W, B, B, m);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   199
        MatMatModM (W, W, W, m);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   200
        n /= 2;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   201
    }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   202
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   203
4221
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   204
static ns3::GlobalValue g_rngSeed ("RngSeed", 
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   205
                                   "The global seed of all rng streams",
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   206
                                   ns3::IntegerValue (1),
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   207
                                   ns3::MakeIntegerChecker<uint32_t> ());
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   208
static ns3::GlobalValue g_rngRun ("RngRun", 
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   209
                                  "The run number used to modify the global seed",
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   210
                                  ns3::IntegerValue (1),
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   211
                                  ns3::MakeIntegerChecker<uint32_t> ());
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   212
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   213
} // end of anonymous namespace
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   214
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   215
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   216
namespace ns3{
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   217
//-------------------------------------------------------------------------
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   218
// Generate the next random number.
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   219
//
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   220
double RngStream::U01 ()
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   221
{
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   222
    int32_t k;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   223
    double p1, p2, u;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   224
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   225
    /* Component 1 */
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   226
    p1 = a12 * Cg[1] - a13n * Cg[0];
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   227
    k = static_cast<int32_t> (p1 / m1);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   228
    p1 -= k * m1;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   229
    if (p1 < 0.0) p1 += m1;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   230
    Cg[0] = Cg[1]; Cg[1] = Cg[2]; Cg[2] = p1;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   231
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   232
    /* Component 2 */
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   233
    p2 = a21 * Cg[5] - a23n * Cg[3];
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   234
    k = static_cast<int32_t> (p2 / m2);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   235
    p2 -= k * m2;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   236
    if (p2 < 0.0) p2 += m2;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   237
    Cg[3] = Cg[4]; Cg[4] = Cg[5]; Cg[5] = p2;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   238
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   239
    /* Combination */
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   240
    u = ((p1 > p2) ? (p1 - p2) * norm : (p1 - p2 + m1) * norm);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   241
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   242
    return (anti == false) ? u : (1 - u);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   243
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   244
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   245
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   246
//-------------------------------------------------------------------------
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   247
// Generate the next random number with extended (53 bits) precision.
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   248
//
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   249
double RngStream::U01d ()
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   250
{
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   251
    double u;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   252
    u = U01();
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   253
    if (anti) {
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   254
        // Don't forget that U01() returns 1 - u in the antithetic case
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   255
        u += (U01() - 1.0) * fact;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   256
        return (u < 0.0) ? u + 1.0 : u;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   257
    } else {
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   258
        u += U01() * fact;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   259
        return (u < 1.0) ? u : (u - 1.0);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   260
    }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   261
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   262
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   263
//-------------------------------------------------------------------------
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   264
// Check that the seeds are legitimate values. Returns true if legal seeds,
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   265
// false otherwise.
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   266
//
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   267
bool RngStream::CheckSeed (const uint32_t seed[6])
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   268
{
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   269
    int i;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   270
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   271
    for (i = 0; i < 3; ++i) {
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   272
        if (seed[i] >= m1) {
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   273
            cerr << "****************************************\n\n"
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   274
                 << "ERROR: Seed[" << i << "] >= 4294967087, Seed is not set."
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   275
                 << "\n\n****************************************\n\n";
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   276
            return (false);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   277
        }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   278
    }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   279
    for (i = 3; i < 6; ++i) {
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   280
        if (seed[i] >= m2) {
1020
ebcb38b7ff7d In some places, print debug messages / errors to stderr, not stdout.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 364
diff changeset
   281
	  cerr << "Seed[" << i << "] = " << seed[i] << endl; 
ebcb38b7ff7d In some places, print debug messages / errors to stderr, not stdout.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 364
diff changeset
   282
          cerr << "*****************************************\n\n"
ebcb38b7ff7d In some places, print debug messages / errors to stderr, not stdout.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 364
diff changeset
   283
               << "ERROR: Seed[" << i << "] >= 4294944443, Seed is not set."
ebcb38b7ff7d In some places, print debug messages / errors to stderr, not stdout.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 364
diff changeset
   284
               << "\n\n*****************************************\n\n";
ebcb38b7ff7d In some places, print debug messages / errors to stderr, not stdout.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 364
diff changeset
   285
          return (false);
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   286
        }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   287
    }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   288
    if (seed[0] == 0 && seed[1] == 0 && seed[2] == 0) {
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   289
         cerr << "****************************\n\n"
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   290
              << "ERROR: First 3 seeds = 0.\n\n"
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   291
              << "****************************\n\n";
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   292
         return (false);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   293
    }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   294
    if (seed[3] == 0 && seed[4] == 0 && seed[5] == 0) {
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   295
         cerr << "****************************\n\n"
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   296
              << "ERROR: Last 3 seeds = 0.\n\n"
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   297
              << "****************************\n\n";
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   298
         return (false);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   299
    }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   300
    return true;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   301
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   302
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   303
uint32_t
4221
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   304
RngStream::EnsureGlobalInitialized (void)
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   305
{
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   306
  static bool initialized = false;
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   307
  static uint32_t run = 0;
4221
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   308
  if (!initialized)
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   309
    {
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   310
      initialized = true;
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   311
      uint32_t seed;
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   312
      // First, initialize ourselves from the global value.
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   313
      {
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   314
        IntegerValue value;
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   315
        g_rngSeed.GetValue (value);
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   316
        seed = value.Get ();
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   317
        g_rngRun.GetValue (value);
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   318
        run = value.Get ();
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   319
      }
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   320
      // then, in case we have NS_RNG set, override the global 
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   321
      // value from the env var.
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   322
      char *tmp = getenv ("NS_RNG");
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   323
      if (tmp != 0)
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   324
        {
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   325
          std::string var = std::string (getenv ("NS_RNG"));
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   326
          std::string::size_type colon = var.find (":");
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   327
          if (colon != std::string::npos)
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   328
            {
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   329
              {
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   330
                std::string seedString = var.substr (0, colon);
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   331
                std::istringstream iss;
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   332
                iss.str (seedString);
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   333
                iss >> seed;
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   334
              }
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   335
              {
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   336
                std::string runString = var.substr (colon+1,var.size ()-colon-1);
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   337
                std::istringstream iss;
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   338
                iss.str (runString);
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   339
                iss >> run;
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   340
              }
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   341
            }
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   342
          else
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   343
            {
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   344
              {
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   345
                std::istringstream iss;
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   346
                iss.str (var);
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   347
                iss >> seed;
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   348
              }
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   349
            }
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   350
        }
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   351
      // finally, actually use these values to do something.
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   352
      uint32_t seedArray [] = {seed, seed, seed, seed, seed, seed};
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   353
      SetPackageSeed (seedArray);
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   354
    }
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   355
  return run;
4221
73b49aa25221 Expose RNG seed/run # to attributes; bindings update
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 1020
diff changeset
   356
}
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   357
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   358
//*************************************************************************
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   359
// Public members of the class start here
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   360
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   361
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   362
//-------------------------------------------------------------------------
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   363
// The default seed of the package; will be the seed of the first
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   364
// declared RngStream, unless SetPackageSeed is called.
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   365
//
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   366
double RngStream::nextSeed[6] =
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   367
{
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   368
  12345.0, 12345.0, 12345.0, 12345.0, 12345.0, 12345.0
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   369
};
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   370
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   371
//-------------------------------------------------------------------------
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   372
// constructor
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   373
//
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   374
RngStream::RngStream ()
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   375
{
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   376
  uint32_t run = EnsureGlobalInitialized ();
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   377
  anti = false;
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   378
  incPrec = false;
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   379
  // Stream initialization moved to separate method.
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   380
  InitializeStream ();
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   381
  ResetNthSubstream (run);
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   382
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   383
360
7bffd987426c Fixed major memory bug and docs in RandomVariable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 346
diff changeset
   384
RngStream::RngStream(const RngStream& r)
7bffd987426c Fixed major memory bug and docs in RandomVariable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 346
diff changeset
   385
{
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   386
  anti = r.anti;
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   387
  incPrec = r.incPrec;
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   388
  for (int i = 0; i < 6; ++i) {
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   389
    Cg[i] = r.Cg[i];
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   390
    Bg[i] = r.Bg[i];
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   391
    Ig[i] = r.Ig[i];
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   392
  }
360
7bffd987426c Fixed major memory bug and docs in RandomVariable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 346
diff changeset
   393
}
7bffd987426c Fixed major memory bug and docs in RandomVariable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 346
diff changeset
   394
      
7bffd987426c Fixed major memory bug and docs in RandomVariable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 346
diff changeset
   395
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   396
void RngStream::InitializeStream()
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   397
{ // Moved from the RngStream constructor above to allow seeding
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   398
  // AFTER the global package seed has been set in the Random
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   399
  // object constructor.
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   400
  /* Information on a stream. The arrays {Cg, Bg, Ig} contain the current
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   401
     state of the stream, the starting state of the current SubStream, and the
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   402
     starting state of the stream. This stream generates antithetic variates
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   403
     if anti = true. It also generates numbers with extended precision (53
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   404
     bits if machine follows IEEE 754 standard) if incPrec = true. nextSeed
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   405
     will be the seed of the next declared RngStream. */
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   406
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   407
  for (int i = 0; i < 6; ++i) {
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   408
    Bg[i] = Cg[i] = Ig[i] = nextSeed[i];
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   409
  }
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   410
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   411
  MatVecModM (A1p127, nextSeed, nextSeed, m1);
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   412
  MatVecModM (A2p127, &nextSeed[3], &nextSeed[3], m2);
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   413
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   414
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   415
//-------------------------------------------------------------------------
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   416
// Reset Stream to beginning of Stream.
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   417
//
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   418
void RngStream::ResetStartStream ()
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   419
{
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   420
  for (int i = 0; i < 6; ++i)
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   421
    Cg[i] = Bg[i] = Ig[i];
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   422
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   423
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   424
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   425
//-------------------------------------------------------------------------
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   426
// Reset Stream to beginning of SubStream.
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   427
//
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   428
void RngStream::ResetStartSubstream ()
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   429
{
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   430
  for (int i = 0; i < 6; ++i)
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   431
    Cg[i] = Bg[i];
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   432
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   433
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   434
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   435
//-------------------------------------------------------------------------
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   436
// Reset Stream to NextSubStream.
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   437
//
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   438
void RngStream::ResetNextSubstream ()
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   439
{
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   440
  MatVecModM(A1p76, Bg, Bg, m1);
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   441
  MatVecModM(A2p76, &Bg[3], &Bg[3], m2);
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   442
  for (int i = 0; i < 6; ++i)
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   443
    Cg[i] = Bg[i];
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   444
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   445
364
9df87117d468 RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 360
diff changeset
   446
//-------------------------------------------------------------------------
9df87117d468 RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 360
diff changeset
   447
// Reset Stream to Nth SubStream.
9df87117d468 RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 360
diff changeset
   448
//
9df87117d468 RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 360
diff changeset
   449
void RngStream::ResetNthSubstream (uint32_t N)
9df87117d468 RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 360
diff changeset
   450
{
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   451
  if(N==0) return;
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   452
  for(uint32_t i=0;i<N;++i) {
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   453
    MatVecModM(A1p76, Bg, Bg, m1);
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   454
    MatVecModM(A2p76, &Bg[3], &Bg[3], m2);
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   455
  }
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   456
  for (int i = 0; i < 6; ++i)
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   457
    Cg[i] = Bg[i];
364
9df87117d468 RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 360
diff changeset
   458
}
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   459
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   460
//-------------------------------------------------------------------------
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   461
bool RngStream::SetPackageSeed (const uint32_t seed[6])
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   462
{
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   463
  EnsureGlobalInitialized ();
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   464
  if (!CheckSeed (seed))
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   465
    {
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   466
      return false;
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   467
    }
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   468
  for (int i = 0; i < 6; ++i)
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   469
    nextSeed[i] = seed[i];
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   470
  return true;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   471
}
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   472
bool 
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   473
RngStream::SetPackageSeed (uint32_t seed)
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   474
{
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   475
  uint32_t seeds[6] = {seed, seed, seed, seed, seed, seed};
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   476
  return SetPackageSeed (seeds);
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   477
}
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   478
void 
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   479
RngStream::GetPackageSeed (uint32_t seed[6])
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   480
{
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   481
  EnsureGlobalInitialized ();
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   482
  for (int i = 0; i < 6; i++)
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   483
    {
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   484
      seed[i] = nextSeed[i];
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   485
    }
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   486
}
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   487
void 
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   488
RngStream::SetPackageRun (uint32_t run)
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   489
{
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   490
  g_rngRun.SetValue (IntegerValue (run));
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   491
}
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   492
uint32_t 
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   493
RngStream::GetPackageRun (void)
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   494
{
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   495
  IntegerValue run;
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   496
  g_rngRun.GetValue (run);
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   497
  return run.Get ();
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   498
}
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   499
bool 
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   500
RngStream::CheckSeed(uint32_t seed)
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   501
{
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   502
  uint32_t seeds[6] = {seed, seed, seed, seed, seed, seed};
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   503
  return CheckSeed (seeds);
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   504
}
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   505
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   506
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   507
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   508
//-------------------------------------------------------------------------
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   509
bool RngStream::SetSeeds (const uint32_t seed[6])
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   510
{
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   511
  if (!CheckSeed (seed)) return false;
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   512
  for (int i = 0; i < 6; ++i)
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   513
    Cg[i] = Bg[i] = Ig[i] = seed[i];
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4222
diff changeset
   514
  return true;
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   515
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   516
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   517
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   518
//-------------------------------------------------------------------------
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   519
// if e > 0, let n = 2^e + c;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   520
// if e < 0, let n = -2^(-e) + c;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   521
// if e = 0, let n = c.
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   522
// Jump n steps forward if n > 0, backwards if n < 0.
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   523
//
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   524
void RngStream::AdvanceState (int32_t e, int32_t c)
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   525
{
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   526
    double B1[3][3], C1[3][3], B2[3][3], C2[3][3];
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   527
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   528
    if (e > 0) {
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   529
        MatTwoPowModM (A1p0, B1, m1, e);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   530
        MatTwoPowModM (A2p0, B2, m2, e);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   531
    } else if (e < 0) {
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   532
        MatTwoPowModM (InvA1, B1, m1, -e);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   533
        MatTwoPowModM (InvA2, B2, m2, -e);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   534
    }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   535
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   536
    if (c >= 0) {
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   537
        MatPowModM (A1p0, C1, m1, c);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   538
        MatPowModM (A2p0, C2, m2, c);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   539
    } else {
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   540
        MatPowModM (InvA1, C1, m1, -c);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   541
        MatPowModM (InvA2, C2, m2, -c);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   542
    }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   543
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   544
    if (e) {
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   545
        MatMatModM (B1, C1, C1, m1);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   546
        MatMatModM (B2, C2, C2, m2);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   547
    }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   548
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   549
    MatVecModM (C1, Cg, Cg, m1);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   550
    MatVecModM (C2, &Cg[3], &Cg[3], m2);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   551
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   552
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   553
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   554
//-------------------------------------------------------------------------
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   555
void RngStream::GetState (uint32_t seed[6]) const
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   556
{
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   557
   for (int i = 0; i < 6; ++i)
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   558
      seed[i] = static_cast<uint32_t> (Cg[i]);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   559
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   560
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   561
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   562
//-------------------------------------------------------------------------
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   563
void RngStream::IncreasedPrecis (bool incp)
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   564
{
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   565
   incPrec = incp;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   566
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   567
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   568
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   569
//-------------------------------------------------------------------------
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   570
void RngStream::SetAntithetic (bool a)
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   571
{
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   572
   anti = a;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   573
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   574
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   575
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   576
//-------------------------------------------------------------------------
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   577
// Generate the next random number.
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   578
//
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   579
double RngStream::RandU01 ()
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   580
{
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   581
   if (incPrec)
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   582
      return U01d();
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   583
   else
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   584
      return U01();
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   585
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   586
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   587
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   588
//-------------------------------------------------------------------------
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   589
// Generate the next random integer.
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   590
//
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   591
int32_t RngStream::RandInt (int32_t low, int32_t high)
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   592
{
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   593
    return low + static_cast<int32_t> ((high - low + 1) * RandU01 ());
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   594
};
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   595
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   596
} //namespace ns3