SUNphi  1.0
MasterRandomGenerator.hpp
Go to the documentation of this file.
1 #ifndef _MASTERRANDOMGENERATOR_HPP
2 #define _MASTERRANDOMGENERATOR_HPP
3 
4 /// \file MasterRandomGenerator.hpp
5 ///
6 /// \brief Master random generator, used to start streams
7 ///
8 /// This random generator is expected to be used few times, so we
9 /// don't care using a slow one not supporting big skip
10 
11 #include <random/TrueRandomGenerator.hpp>
12 #include <Serialize.hpp>
13 
14 namespace SUNphi
15 {
16  /// Inner generator used
18  std::mt19937_64;
19 
20  /// Master random generator
24  {
25  /// Number of seeds needed to initialize the state
26  static constexpr int nSeeds=
28 
29  /// Seed state
31 
32  /// Constant access to the seeds
34  _seeds;
35 
36  /// Base random generator
37  using Base=
39 
40  public:
41 
43 
44  /// Reset the number generator to the initial state
45  void reset()
46  {
47  // Prepares a seed sequence to initialize
48  std::seed_seq dseeds(seeds.begin(),seeds.end());
49 
50  this->seed(dseeds);
51  }
52 
53  /// Skip n elements
54  void skip(const int n)
55  {
56  for(int i=0;i<n;i++)
57  (*this)();
58  }
59 
60  /// Fills _seeds using the true random generator
62  {
63  std::generate(_seeds().begin(),_seeds().end(),std::ref(trueRandomGenerator));
64 
65  reset();
66  }
67  };
68 }
69 
70 #endif
void reset()
Reset the number generator to the initial state.
#define LIST_SERIALIZABLE_MEMBERS(...)
Defines a list of serializable members.
Definition: Map.hpp:203
#define SERIALIZABLE_SCALAR_WITH_TAG(TYPE, NAME, TAG,...)
Defines a serializable scalar with an explicit tag.
Definition: Scalar.hpp:15
void skip(const int n)
Skip n elements.
const std::vector< uint64_t > & seeds
Constant access to the seeds.
decltype(auto) operator+(T1 &&smet1, T2 &&smet2)
Implement smet1+smet2.
Definition: Add.hpp:87
MasterRandomGenerator()
Fills _seeds using the true random generator.