SMACC
Loading...
Searching...
No Matches
eg_random_generator.cpp
Go to the documentation of this file.
2
3namespace smacc
4{
5 namespace state_reactors
6 {
7 EgRandomGenerator::EgRandomGenerator(RandomGenerateReactorMode mode, double evAMin, double evAMax, double evBMin, double evBMax, double evCMin, double evCMax)
8 :
9 mode_(mode),
10 evAMin_(evAMin),
11 evAMax_(evAMax),
12 evBMin_(evBMin),
13 evBMax_(evBMax),
14 evCMin_(evCMin),
15 evCMax_(evCMax)
16 {
17
18 auto values = {evAMin, evAMax, evBMin, evBMax, evCMin, evCMax};
19
20 this->minValue = std::numeric_limits<double>::max();
21 this->maxValue = std::numeric_limits<double>::min();
22 for (auto &v : values)
23 {
24 if (v < minValue)
25 {
26 minValue = v;
27 }
28
29 if (v > maxValue)
30 {
31 maxValue = v;
32 }
33 }
34 }
35
37 {
38 int range = this->maxValue - this->minValue;
39 int result = (rand() % range) + minValue;
40
41 if (result >= evAMin_ && result <= evAMax_)
42 {
43 this->postEventA();
44 }
45
46 if (result >= evBMin_ && result <= evBMax_)
47 {
48 this->postEventB();
49 }
50
51 if (result >= evCMin_ && result <= evCMax_)
52 {
53 this->postEventC();
54 }
55 }
56
58 {
60 {
61 this->postRandomEvents();
62 }
63 }
64
66 {
68 {
69 this->postRandomEvents();
70 }
71 }
72 } // namespace state_reactors
73} // namespace smacc
EgRandomGenerator(RandomGenerateReactorMode mode, double evAMin=1, double evAMax=4, double evBMin=5, double evBMax=8, double evCMin=9, double evCMax=12)