5#include "matpack_concepts.h"
21template <std::uniform_random_bit_generator Generator = std::mt19937_64>
23 using int_t =
typename Generator::result_type;
25 static constexpr int_t min_v = std::numeric_limits<int_t>::lowest();
26 static constexpr int_t max_v = std::numeric_limits<int_t>::max();
56 std::lock_guard lock{rng.
g};
66 const std::lock_guard my_lock(this->g);
67 return Generator{std::uniform_int_distribution<int_t>(
min_v,
max_v)(
v)};
100 template <
template <
typename>
101 class random_distribution = std::uniform_real_distribution,
103 auto get(Ts &&...x)
const {
105 draw = random_distribution(std::forward<Ts>(x)...)]()
mutable {
125 static std::mutex seed_mtx;
126 static std::vector<int_t> seeds{};
128 std::lock_guard class_lock{
g};
129 std::lock_guard method_lock{seed_mtx};
130 bool seed_as_is =
true;
132 constexpr auto add_one = [](
int_t i) {
136 if (std::find(seeds.begin(), seeds.end(), n) != seeds.end()) {
139 auto minmax = std::minmax_element(seeds.begin(), seeds.end());
145 }
else if (
static_cast<std::size_t
>(
max -
min) <= seeds.size()) {
152 }
while (std::find(seeds.begin(), seeds.end(), n) != seeds.end());
201template <std::size_t N,
203 class random_distribution = std::uniform_real_distribution,
204 std::uniform_random_bit_generator Generator = std::mt19937_64,
206 class T =
decltype(RNG{}.template get<random_distribution>(
207 param_types{}...)())>
209 param_types &&...x) {
210 matpack::matpack_data<T, N> out(sz);
211 std::generate(out.elem_begin(), out.elem_end(),
212 RNG{}.template get<random_distribution>(
213 std::forward<param_types>(x)...));
221template <
template <
typename>
222 class random_distribution = std::uniform_real_distribution,
223 std::uniform_random_bit_generator Generator = std::mt19937_64,
224 typename... param_types>
226 return random_numbers<1, random_distribution, Generator>(
227 std::array<Index, 1>{n}, std::forward<param_types>(x)...);
base max(const Array< base > &x)
Max function.
base min(const Array< base > &x)
Min function.
Stuff related to time in ARTS.
A C++ standards dependent random number generator class.
static constexpr int_t max_v
friend std::ostream & operator<<(std::ostream &os, const RandomNumberGenerator &rng)
output the current seed
bool seed(const Time &t={})
As the main seed, but the number is extracted from the time.
auto get(Ts &&...x) const
Returns a random number generator of some random distribution.
bool seed(int_t n)
Seeds the random number engine with a new and unique seed.
Generator new_generator() const
Returns a new Generator.
typename Generator::result_type int_t
RandomNumberGenerator(const int_t &s)
Construct a new Random Number Generator object.
RandomNumberGenerator(const RandomNumberGenerator &rng)
Copy a Random Number Generator object.
RandomNumberGenerator(const Time &t={})
Construct a new Random Number Generator object.
static constexpr int_t min_v
void force_seed(int_t n)
Force the seed to some integer, determining the randomness of the distributions.
Helper macros for debugging.
matpack::matpack_data< T, N > random_numbers(std::array< Index, N > sz, param_types &&...x)
Wraps the generation of a random number generator for a matpack type.
Class to handle time in ARTS.