Project

General

Profile

Statistics
| Branch: | Revision:

root / src / envir / akaroarng.cc @ 636cbdd5

History | View | Annotate | Download (2.13 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::selfTest()
48
{
49
    // Akaroa doesn't provide self-test capability
50
}
51

    
52
unsigned long cAkaroaRNG::intRand()
53
{
54
    numDrawn++;
55
    return AkRandom()-1;
56
}
57

    
58
unsigned long cAkaroaRNG::intRandMax()
59
{
60
    return 0x7ffffffeUL; // 2^31-2
61
}
62

    
63
unsigned long cAkaroaRNG::intRand(unsigned long n)
64
{
65
    // UniformInt() is also from Akaroa, and it's based on AkRandomReal()
66
    numDrawn++;
67
    return UniformInt(0, n-1);
68
}
69

    
70
double cAkaroaRNG::doubleRand()
71
{
72
    // khmm, this cannot return zero, but we cannot do better... see class doc.
73
    numDrawn++;
74
    return AkRandomReal();
75
}
76

    
77
double cAkaroaRNG::doubleRandNonz()
78
{
79
    numDrawn++;
80
    return AkRandomReal();
81
}
82

    
83
double cAkaroaRNG::doubleRandIncl1()
84
{
85
    // khmm, this cannot return 1, but we cannot do better... see class doc.
86
    numDrawn++;
87
    return AkRandomReal();
88
}
89

    
90
#endif
91