Skip to content

MT19937

Abstract Scheme of the MT19937

Scalar

namespace pxart {

struct mt19937;

}

Include Scheme

#include <pxart/mt19937.hpp>

Member Types

using uint_type = uint32_t;
using result_type = uint_type;
struct default_seeder;

Member Functions

Construction and Seeding

constexpr mt19937();
Default constructor which uses a default-initialized pxart::mt19937::default_seeder.


template <typename RNG>
constexpr explicit mt19937(RNG&& rng);
Initialize the PRNG by any other seeder or RNG.

Generation

constexpr result_type operator()() noexcept;
Return pseudorandom numbers and advance the state of the generator.

Characteristics

constexpr result_type min() noexcept;
constexpr result_type max() noexcept;
Return the output range of pseudorandom numbers.

Notes

pxart::mt19937 used with pxart::mt19937::default_seeder produces exactly the same results as std::mt19937 from the C++ STL.

Example

#include <iomanip>
#include <iostream>
#include <random>
//
#include <pxart/mt19937.hpp>
#include <pxart/uniform.hpp>

using namespace std;

int main() {
  // Properly initialize pxart PRNG.
  pxart::mt19937 rng{std::random_device{}};
  // Print some uniformly distributed random numbers.
  for (size_t i = 0; i < 10; ++i)
    cout << setw(20) << pxart::uniform<float>(rng) << '\n';
}

Last update: January 18, 2021