Statistics
| Branch: | Revision:

root / src / envir / akaroarng.cc @ a787bc0a

History | View | Annotate | Download (2.55 KB)

1
//==========================================================================
2
//  AKAROARNG.CC - part of
3
//                 OMNeT++/OMNEST
4
//              Discrete System Simulation in C++
5
//
6
// Contents:
7
//   class cAkaroaRNG
8
//
9
//  Author: Andras Varga
10
//
11
//==========================================================================
12

    
13
/*--------------------------------------------------------------*
14
  Copyright (C) 2002-2008 Andras Varga
15
  Copyright (C) 2006-2008 OpenSim Ltd.
16

17
  This file is distributed WITHOUT ANY WARRANTY. See the file
18
  `license' for details on this and other legal matters.
19
*--------------------------------------------------------------*/
20

    
21
#ifdef WITH_AKAROA
22

    
23
#include <akaroa.H>
24
#include <akaroa/distributions.H>  // for UniformInt()
25
#include "cenvir.h"
26
#include "regmacros.h"
27
#include "globals.h"
28
#include "simutil.h"
29
#include "cexception.h"
30
#include "akaroarng.h"
31

    
32
USING_NAMESPACE
33

    
34

    
35
Register_Class(cAkaroaRNG);
36

    
37

    
38
void cAkaroaRNG::initialize(int runNumber, int rngId, int numRngs,
39
                            int parsimProcId, int parsimNumPartitions,
40
                            cConfiguration *cfg)
41
{
42
    // no manual seeding, and only one RNG stream
43
    if (numRngs!=1 || rngId!=0 || parsimNumPartitions>1)
44
        throw cRuntimeError("cAkaroaRNG: Akaroa supports only one RNG stream, use num-rngs=1 setting");
45
}
46

    
47
void cAkaroaRNG::initializeAsMaster(int runNumber, int rngId, int numRngs,
48
                        int parsimProcId, int parsimNumPartitions,
49
                        cConfiguration *cfg)
50
{
51
    // just call initialize as Akaroa doesn't use manual seeding
52
    initialize(runNumber, rngId, numRngs, parsimProcId, parsimNumPartitions, cfg);
53
}
54

    
55
void cAkaroaRNG::selfTest()
56
{
57
    // Akaroa doesn't provide self-test capability
58
}
59

    
60
unsigned long cAkaroaRNG::intRand()
61
{
62
    numDrawn++;
63
    return AkRandom()-1;
64
}
65

    
66
unsigned long cAkaroaRNG::intRandMax()
67
{
68
    return 0x7ffffffeUL; // 2^31-2
69
}
70

    
71
unsigned long cAkaroaRNG::intRand(unsigned long n)
72
{
73
    // UniformInt() is also from Akaroa, and it's based on AkRandomReal()
74
    numDrawn++;
75
    return UniformInt(0, n-1);
76
}
77

    
78
double cAkaroaRNG::doubleRand()
79
{
80
    // khmm, this cannot return zero, but we cannot do better... see class doc.
81
    numDrawn++;
82
    return AkRandomReal();
83
}
84

    
85
double cAkaroaRNG::doubleRandNonz()
86
{
87
    numDrawn++;
88
    return AkRandomReal();
89
}
90

    
91
double cAkaroaRNG::doubleRandIncl1()
92
{
93
    // khmm, this cannot return 1, but we cannot do better... see class doc.
94
    numDrawn++;
95
    return AkRandomReal();
96
}
97

    
98
void cAkaroaRNG::seed(unsigned long seed)
99
{
100
    // Akaroa doesn't support manual seeding
101
}
102

    
103
#endif
104