Linear Congruential Generator¶
Scalar¶
namespace pxart {
template <typename Result_type, typename Uint_type,
Uint_type a, Uint_type c, Uint_type m>
struct lcg;
using minstd_rand = lcg<uint32_t, uint64_t, 48271, 0, 2147483647>;
}
Include Scheme¶
#include <pxart/lcg.hpp>
Member Types¶
using uint_type = Uint_type;
using result_type = Result_type;
Member Functions¶
Construction and Seeding¶
constexpr lcg();
constexpr explicit lcg(uint_type seed) noexcept;
Generation¶
constexpr result_type operator()() noexcept;
Example¶
#include <iomanip>
#include <iostream>
#include <random>
//
#include <pxart/lcg.hpp>
#include <pxart/uniform.hpp>
using namespace std;
int main() {
// Properly initialize pxart PRNG.
pxart::minstd_rand 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