blob: 6f1ef7ee3de0e4a49d3f0a29588e1b32bcfd08bd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
#pragma once
#include <concepts>
#include <type_traits>
namespace floormat {
struct random_engine
{
virtual ~random_engine();
virtual std::common_type_t<size_t, uintptr_t, ptrdiff_t> operator()() = 0;
template<std::integral T>
requires (sizeof(T) <= sizeof(size_t))
T operator()(T max) {
return static_cast<T>(operator()() % static_cast<size_t>(max));
}
template<std::integral T>
requires (sizeof(T) <= sizeof(size_t))
T operator()(T min, T max) {
return min + operator()(max-min);
}
virtual float operator()(float min, float max) = 0;
};
[[maybe_unused]] extern random_engine& random; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
} // namespace floormat
|