28 using boost::optional;
32 RandomEngine::RandomEngine()
33 : m_seed(1U), m_type_id(
TypeId::mrg2)
37 const size_t nthreads = 1;
39 this->m_lcg64.resize(nthreads);
40 this->m_lcg64_shift.resize(nthreads);
41 this->m_mrg2.resize(nthreads);
42 this->m_mrg3.resize(nthreads);
43 this->m_yarn2.resize(nthreads);
44 this->m_yarn3.resize(nthreads);
56 ss << m_lcg64[0];
break;
57 case TypeId::lcg64_shift :
58 ss << m_lcg64_shift[0];
break;
60 ss << m_mrg2[0];
break;
62 ss << m_mrg3[0];
break;
64 ss << m_yarn2[0];
break;
66 ss << m_yarn3[0];
break;
70 info.state = ss.str();
77 m_type_id = TypeId::mrg2;
86 const string type = pt.get<
string>(
"type");
89 optional<unsigned long> seed = pt.get_optional<
unsigned long>(
"seed");
97 optional<const ptree&> re_pt = pt.get_child_optional(
"state");
99 SetState(re_pt.get().get_value<
string>());
114 template <
typename T>
115 void para_seed(std::vector<T>& rngs,
const unsigned long seed)
119 const size_t n = rngs.size();
121 for (
size_t i = 0; i < n; ++i) {
127 void RandomEngine::SetState(
unsigned long seed)
132 case TypeId::lcg64_shift :
151 template <
typename T>
152 void para_seed(std::vector<T>& rngs,
const std::string& state)
154 stringstream ss(state);
157 const size_t n = rngs.size();
159 for (
size_t i = 0; i < n; ++i) {
165 void RandomEngine::SetState(
const string& state)
170 case TypeId::lcg64_shift :
Type FromString(string s)
Converts a string with name to WallType::Type value.
string ToString(Type w)
Converts a WallType::Type value to corresponding name.
Interface of RandomEngine.
Namespace for the core simulator.
bool Reinitialize()
Reset to the default engine (trng::mrg2 with seed 1).
Namespace for Types of random engines.
TypeId
Enumerates type ids.
std::time_t ToTimeT() const
Returns time stamp as a time_t.
Provides wall-clock time stamp using the time call.
RandomEngineType::Info GetInfo() const
Return the state of the random engine.
void para_seed(std::vector< T > &rngs, const unsigned long seed)
Seed a vector of random number generators and splits in 'n' parallel streams using the leapfrog schem...
Namespace for clock and timekeeping related classes.
bool IsExisting(std::string s)
Check whether type with name s exists.