Statistics
| Branch: | Revision:

root / include / cmersennetwister.h @ fbe00e73

History | View | Annotate | Download (2.58 KB)

1
//==========================================================================
2
//  CMERSENNETWISTER.CC - part of
3
//                 OMNeT++/OMNEST
4
//              Discrete System Simulation in C++
5
//
6
// Contents:
7
//   class cMersenneTwister
8
//
9
//==========================================================================
10

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

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

    
19
#ifndef __CMERSENNETWISTER_H
20
#define __CMERSENNETWISTER_H
21

    
22
#include "simkerneldefs.h"
23
#include "globals.h"
24
#include "crng.h"
25
#include "cconfiguration.h"
26
#include "mersennetwister.h"
27

    
28
NAMESPACE_BEGIN
29

    
30

    
31
/**
32
 * Wraps the Mersenne Twister RNG by Makoto Matsumoto and Takuji Nishimura.
33
 * Cycle length is 2^19937-1, and 623-dimensional equidistribution property
34
 * is assured.
35
 *
36
 * http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/ewhat-is-mt.html
37
 *
38
 * Actual code used is MersenneTwister.h from Richard J. Wagner,
39
 * v1.0, 15 May 2003, rjwagner@writeme.com.
40
 *
41
 * http://www-personal.engin.umich.edu/~wagnerr/MersenneTwister.html
42
 */
43
class SIM_API cMersenneTwister : public cRNG
44
{
45
  protected:
46
    MTRand rng;
47

    
48
  public:
49
    cMersenneTwister() {}
50
    virtual ~cMersenneTwister() {}
51

    
52

    
53
         /**
54
         * Called by the simulation framework to set up this RNG as the central
55
         * seed generating RNG.
56
         */
57
    virtual void initializeAsMaster(int runNumber, int rngId, int numRngs,
58
                               int parsimProcId, int parsimNumPartitions, cConfiguration *cfg);
59

    
60
    /** Sets up the RNG. */
61
    virtual void initialize(int seedSet, int rngId, int numRngs,
62
                            int parsimProcId, int parsimNumPartitions,
63
                            cConfiguration *cfg);
64

    
65
    /** Tests correctness of the RNG */
66
    virtual void selfTest();
67

    
68
    /** Random integer in the range [0,intRandMax()] */
69
    virtual unsigned long intRand();
70

    
71
    /** Maximum value that can be returned by intRand() */
72
    virtual unsigned long intRandMax();
73

    
74
    /** Random integer in [0,n), n < intRandMax() */
75
    virtual unsigned long intRand(unsigned long n);
76

    
77
    /** Random double on the [0,1) interval */
78
    virtual double doubleRand();
79

    
80
    /** Random double on the (0,1) interval */
81
    virtual double doubleRandNonz();
82

    
83
    /** Random double on the [0,1] interval */
84
    virtual double doubleRandIncl1();
85

    
86
    /** set seed without using initialize */
87
    virtual void seed(unsigned long seed);
88
};
89

    
90
NAMESPACE_END
91

    
92

    
93
#endif
94