OMNeT++ Simulation Library  6.0.3
clcg32.h
1 //==========================================================================
2 // CLCG32.CC - part of
3 // OMNeT++/OMNEST
4 // Discrete System Simulation in C++
5 //
6 //==========================================================================
7 
8 /*--------------------------------------------------------------*
9  Copyright (C) 2002-2017 Andras Varga
10  Copyright (C) 2006-2017 OpenSim Ltd.
11 
12  This file is distributed WITHOUT ANY WARRANTY. See the file
13  `license' for details on this and other legal matters.
14 *--------------------------------------------------------------*/
15 
16 #ifndef __OMNETPP_CLCG32_H
17 #define __OMNETPP_CLCG32_H
18 
19 #include "simkerneldefs.h"
20 #include "globals.h"
21 #include "crng.h"
22 #include "cconfiguration.h"
23 
24 namespace omnetpp {
25 
26 
27 #define LCG32_MAX 0x7ffffffeL /* = 2^31-2 */
28 
42 class SIM_API cLCG32 : public cRNG
43 {
44  protected:
45  int32_t seed;
46 
47  // 256 pre-generated seeds, spaced 8,388,608 values in the sequence.
48  // This covers the whole RNG period. Enough for 128 runs with 2 RNGs
49  // each, or 64 runs with 4 RNGs each -- assuming one run never uses
50  // more than 8 million random numbers per RNG.
51  static int32_t autoSeeds[256];
52 
53  public:
54  cLCG32() {}
55  virtual ~cLCG32() {}
56 
58  virtual void initialize(int seedSet, int rngId, int numRngs,
59  int parsimProcId, int parsimNumPartitions,
60  cConfiguration *cfg) override;
61 
63  virtual void selfTest() override;
64 
66  virtual uint32_t intRand() override;
67 
69  virtual uint32_t intRandMax() override;
70 
72  virtual uint32_t intRand(uint32_t n) override;
73 
75  virtual double doubleRand() override;
76 
78  virtual double doubleRandNonz() override;
79 
81  virtual double doubleRandIncl1() override;
82 };
83 
84 } // namespace omnetpp
85 
86 
87 #endif
88 
89 
omnetpp::cConfiguration
Represents the configuration, as accessed by the simulation kernel.
Definition: cconfiguration.h:76
omnetpp::cLCG32
Implements a 32-bit (2^31-2 cycle length) linear congruential random number generator.
Definition: clcg32.h:42
omnetpp::cRNG
Abstract interface for random number generator classes.
Definition: crng.h:48