Statistics
| Branch: | Revision:

root / src / envir / akaroarng.h @ fbe00e73

History | View | Annotate | Download (2.95 KB)

1
//==========================================================================
2
//  AKAROARNG.H - 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
#ifndef __AKAROARNG_H
24
#define __AKAROARNG_H
25

    
26
#include "envirdefs.h"
27
#include "simkerneldefs.h"
28
#include "crng.h"
29
#include "cconfiguration.h"
30

    
31
NAMESPACE_BEGIN
32

    
33

    
34
/**
35
 * Wraps Akaroa's random number generator.
36
 *
37
 * Akaroa 2.7.4 provides only one RNG stream, and the available functions
38
 * are (from <tt>src/akaroa/random.H</tt>):
39
 *
40
 * <pre>
41
 * real AkRandomReal();      // float 0 < x < 1
42
 * unsigned long AkRandom(); // integer 0 < x < 2^31-1
43
 * </pre>
44
 *
45
 * The second (integer) form is probably better be avoided, because it is
46
 * coded as:
47
 *
48
 * <pre>
49
 * unsigned long AkRandom() {
50
 *     return (unsigned long)(AkRandomReal() * 0x7fffffff);
51
 * }
52
 * </pre>
53
 *
54
 * The <tt>doubleRand()</tt>, <tt>doubleRandNonz()</tt>, <tt>doubleRandIncl1()</tt>
55
 * methods in this class just invoke <tt>AkRandomReal()</tt>, so contrary to their
56
 * specifications they won't return either 0 or 1.
57
 */
58
class ENVIR_API cAkaroaRNG : public cRNG
59
{
60
  public:
61
    cAkaroaRNG() {}
62
    virtual ~cAkaroaRNG() {}
63

    
64
    /** Sets up the RNG. */
65
    virtual void initialize(int runNumber, int rngId, int numRngs,
66
                            int parsimProcId, int parsimNumPartitions,
67
                            cConfiguration *cfg);
68

    
69
    /**
70
     * Called by the simulation framework to set up this RNG as the central
71
     * seed generating RNG.
72
     */
73
    virtual void initializeAsMaster(int runNumber, int rngId, int numRngs,
74
                                    int parsimProcId, int parsimNumPartitions,
75
                                    cConfiguration *cfg);
76

    
77
    /** Tests correctness of the RNG */
78
    virtual void selfTest();
79

    
80
    /** Random integer in the range [0,intRandMax()] */
81
    virtual unsigned long intRand();
82

    
83
    /** Maximum value that can be returned by intRand() */
84
    virtual unsigned long intRandMax();
85

    
86
    /** Random integer in [0,n), n < intRandMax() */
87
    virtual unsigned long intRand(unsigned long n);
88

    
89
    /** Invokes AkRandomReal(), so sadly, it actually cannot return 0. */
90
    virtual double doubleRand();
91

    
92
    /** Invokes AkRandomReal(). */
93
    virtual double doubleRandNonz();
94

    
95
    /** Invokes AkRandomReal(), so sadly, it actually cannot return either 0 or 1. */
96
    virtual double doubleRandIncl1();
97

    
98
    /** set seed without using initialize */
99
    virtual void seed(unsigned long seed);
100
};
101

    
102
NAMESPACE_END
103

    
104
#endif
105

    
106
#endif