MT19937 Default Seeder¶
The purpose of pxart::mt19937::default_seeder
is to provide reasonable pseudorandom seeds based on a single truly or fixed seed value. It is implemented in such a way that pxart::mt19937
outputs the same values in the same order as std::mt19937
when pxart::mt19937::default_seeder
is initialized with the same integer value than std::mt19937
.
Note
We do not recommend to use pxart::mt19937::default_seeder
because it only uses a single seed value. Hence, we designed the interface to be a little bit more complicated to emphasize the seeding mechanism. It is implemented for the sake of completeness. Instead you should use pxart::seed_seq
.
namespace pxart {
struct mt19937::default_seeder;
}
Include Scheme¶
#include <pxart/mt19937.hpp>
Member Functions¶
Construction¶
constexpr default_seeder();
constexpr explicit default_seeder(uint_type s);
Generation¶
constexpr uint_type operator()() noexcept;
Characteristics¶
constexpr uint_type min() noexcept;
constexpr uint_type max() noexcept;
Example¶
#include <iomanip>
#include <iostream>
#include <random>
//
#include <pxart/mt19937.hpp>
using namespace std;
int main() {
// Best case: Generate truly random seed.
const auto seed = std::random_device{}();
// Generate std PRNG to compare against.
std::mt19937 std_rng{seed};
// Generate pxart PRNG with the default seeder and the same seed.
pxart::mt19937::default_seeder seeder{seed};
pxart::mt19937 rng{seeder};
// Print some pseudorandom numbers of the standard generator and the pxart
// generator to compare them and show that they are equal.
for (size_t i = 0; i < 10; ++i)
cout << setw(20) << std_rng() << setw(20) << rng() << '\n';
}
Last update: January 18, 2021