nx_metadata_sdk 1.0 Metadata SDK

random_state_changer.h
1 // Copyright 2018-present Network Optix, Inc. Licensed under MPL 2.0: www.mozilla.org/MPL/2.0/
2
3 #pragma once
4
5 #include <random>
6
7 namespace nx {
8 namespace vms_server_plugins {
9 namespace analytics {
10 namespace stub {
11
12 class RandomStateChanger
13 {
14 public:
15 RandomStateChanger(int randModulus = 7, int maxNumberOfStateChanges = 4):
16 m_randModulus(randModulus),
17 m_maxStateChanges(maxNumberOfStateChanges)
18 {
19 }
20
21 void update()
22 {
23 m_stateChanged = m_maxStateChanges >= 0
24 ? rand() % m_randModulus == 0
25 : false;
26
27 if (m_stateChanged)
28 --m_maxStateChanges;
29 }
30
31 bool stateChanged() const
32 {
33 return m_stateChanged;
34 }
35
36 private:
37 const int m_randModulus;
38 int m_maxStateChanges;
39 bool m_stateChanged = false;
40 };
41
42 } // namespace stub
43 } // namespace analytics
44 } // namespace vms_server_plugins
45 } // namespace nx
nx
Definition: apple_utils.h:6
nx::vms_server_plugins::analytics::stub::RandomStateChanger
Definition: random_state_changer.h:12