numerics
Loading...
Searching...
No Matches
rng.hpp
Go to the documentation of this file.
1/// @file markov/rng.hpp
2/// @brief RNG seeding utilities for MCMC simulations.
3#pragma once
4#include <random>
5
6namespace num::markov {
7
8/// @brief Construct an RNG seeded from hardware entropy.
9///
10/// Equivalent to `RNG(std::random_device{}())`. Use this at simulation
11/// startup for non-deterministic seeds.
12///
13/// @tparam RNG Any standard-library-compatible random number engine.
14/// Defaults to std::mt19937.
15template<typename RNG = std::mt19937>
17 std::random_device rd;
18 return RNG(rd());
19}
20
21/// @brief Construct an RNG from a fixed seed (for reproducible runs).
22template<typename RNG = std::mt19937>
23RNG make_rng(typename RNG::result_type seed) {
24 return RNG(seed);
25}
26
27} // namespace num::markov
RNG make_seeded_rng()
Construct an RNG seeded from hardware entropy.
Definition rng.hpp:16
RNG make_rng(typename RNG::result_type seed)
Construct an RNG from a fixed seed (for reproducible runs).
Definition rng.hpp:23
constexpr T ipow(T x) noexcept
Compute x^N at compile time via repeated squaring.