Skip to content

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();
Default constructor uses a default seed value and the one-parameter constructor.


constexpr explicit default_seeder(uint_type s);
Initializes the object by a single given integer.

Generation

constexpr uint_type operator()() noexcept;
Generates reasonable pseudorandom seed values for the MT19937 based on a single fixed value or a single truly random seed.

Characteristics

constexpr uint_type min() noexcept;
constexpr uint_type max() noexcept;
These functions return the output range of the seeder.

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