MarlinMT  0.1.0
RandomSeedManager.h
Go to the documentation of this file.
1 #ifndef MARLINMT_RANDOMSEEDMANAGER_h
2 #define MARLINMT_RANDOMSEEDMANAGER_h 1
3 
4 // -- std headers
5 #include <map>
6 #include <random>
7 #include <memory>
8 #include <functional>
9 #include <unordered_set>
10 
11 namespace marlinmt {
12 
13  class EventStore ;
14 
19  public:
20  RandomSeedManager(const RandomSeedManager&) = delete ;
22  ~RandomSeedManager() = default ;
23 
24  public:
25  // typedefs
26  typedef unsigned int SeedType ;
27  typedef std::hash<const void*> HashFunction ;
28  typedef const void * HashArgument ;
29  typedef std::size_t HashResult ;
30  typedef std::unordered_set<HashResult> EntryList ;
31  typedef std::map<HashResult, SeedType> RandomSeedMap ;
32  typedef std::mt19937 RandomGenerator ;
33  typedef std::uniform_int_distribution<SeedType> RandomDistribution ;
34  // constants
35  static const SeedType MinSeed = 0 ;
36  static const SeedType MaxSeed = std::numeric_limits<SeedType>::max() ;
37 
38  public:
44  RandomSeedManager( SeedType globalSeed = static_cast<unsigned int>(time(nullptr)) ) ;
45 
51  void addEntry( HashResult entry ) ;
52 
58  void addEntry( HashArgument arg ) ;
59 
67  std::unique_ptr<RandomSeedMap> generateRandomSeeds( const EventStore * const evt ) ;
68 
69  private:
73  SeedType getRandom() ;
74 
75  private:
77  SeedType _globalSeed {0} ;
79  EntryList _entryList {} ;
81  RandomGenerator _generator {_globalSeed} ;
83  RandomDistribution _rdmDistribution {MinSeed, MaxSeed} ;
84  };
85 
86 } // end namespace marlinmt
87 
88 #endif
std::map< HashResult, SeedType > RandomSeedMap
RandomDistribution _rdmDistribution
The random number distribution.
std::hash< const void * > HashFunction
std::unordered_set< HashResult > EntryList
std::unique_ptr< RandomSeedMap > generateRandomSeeds(const EventStore *const evt)
Generate a random seed map.
static const SeedType MaxSeed
void addEntry(HashResult entry)
Add an entry to the random seed manager.
std::uniform_int_distribution< SeedType > RandomDistribution
EntryList _entryList
The entry list.
RandomSeedManager class.
RandomGenerator _generator
The random generator engine.
RandomSeedManager & operator=(const RandomSeedManager &)=delete
static const SeedType MinSeed
SeedType _globalSeed
The global random seed, if set.
SeedType getRandom()
Get a new random number from the internal generator.
EventStore class.
Definition: EventStore.h:17
RandomSeedManager(const RandomSeedManager &)=delete