Skip to content

Random Device

The C++ STL provides std::random_device as a default seeding structure. For a lot of platforms, std::random_device returns truly random numbers and should be used for proper seeding of other PRNGs. Some are only providing deterministic behavior. So an alternative seeding strategy should be used for such platforms.

Example

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

using namespace std;

int main() {
  // Create pxart PRNG and seed it by using std::random_device.
  pxart::mt19937 rng{std::random_device{}};
  // Print some random numbers.
  for (size_t i = 0; i < 10; ++i) cout << setw(20) << rng() << '\n';
}

Last update: January 18, 2021