diff options
Diffstat (limited to 'src/random.hpp')
| -rw-r--r-- | src/random.hpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/random.hpp b/src/random.hpp new file mode 100644 index 00000000..3616aabf --- /dev/null +++ b/src/random.hpp @@ -0,0 +1,32 @@ +#pragma once +#include <cstddef> +#include <concepts> +#include <type_traits> + +namespace floormat { + +struct random_engine +{ + virtual inline ~random_engine(); + virtual std::common_type_t<std::size_t, std::uintptr_t, std::ptrdiff_t> operator()() = 0; + + template<std::integral T> + requires (sizeof(T) <= sizeof(std::size_t)) + T operator()(T max) { + return static_cast<T>(operator()() % static_cast<std::size_t>(max)); + } + + template<std::integral T> + requires (sizeof(T) <= sizeof(std::size_t)) + T operator()(T min, T max) { + return min + operator()(max-min); + } + + virtual float operator()(float min, float max) = 0; +}; + +random_engine::~random_engine() = default; + +[[maybe_unused]] extern random_engine& random; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) + +} // namespace floormat |
