|
template<typename CharT , typename Traits > |
std::basic_ostream< CharT, Traits > & | operator<< (std::basic_ostream< CharT, Traits > &os, const SeedGenerator< ID, ResultType > &sg) |
|
template<typename CharT , typename Traits > |
std::basic_istream< CharT, Traits > & | operator>> (std::basic_istream< CharT, Traits > &is, SeedGenerator< ID, ResultType > &sg) |
|
template<typename ID, typename ResultType = unsigned>
class vsmc::SeedGenerator< ID, ResultType >
Seed generator.
Let \(S\) be the current internal seed, an integer in the range between 1 and \(S_{\mathrm{max}}\) where \(S_{\mathrm{max}}\) is the maximum of the internal seed. Each time get()
is called, the internal is first increased by 1. If it is already equal to \(S_{\mathrm{max}}\), then it is set to 1. The output seed is \(S \times D + R\) where \(D\) is the divisor and \(R\) is the remainder. In other words, the output seed belongs to the equivalent class \(S\ \mathrm{mod}\ D \equiv R\). The divisor and the remainder can be set through the modulo(div, rem)
member function.
This property is useful when using programming models such as MPI where one want to have distinct seeds across nodes. Each process can then configure the SeedGenerator using the modulo
member such that \(D\) is the number of total nodes and \(R\) is the rank of each node, counting from zero.
For multithreading programs, the access to this member function shall be protected by mutex, if it is called from multiple threads. Or one can use distinct type ID
to initialized distinct SeedGenerator instances.
Definition at line 85 of file seed.hpp.
template<typename ID, typename ResultType = unsigned>
Set the internal seed.
If seed
is larger than the maximum of the internal seed, than it will be round up to fit into the range. For example, say the range is from 1 to 1000, and the new internal seed is 6061, it will be round up to 61.
Definition at line 133 of file seed.hpp.