#pragma once #include #include #include #include namespace ift630 { template auto random(RNG &&rng, const T lower_bound, const T upper_bound) noexcept -> T { static_assert(std::is_arithmetic::value); static_assert(!std::is_same::value); auto dist = [lower_bound, upper_bound]() { if constexpr (std::is_floating_point::value) { return std::uniform_real_distribution{lower_bound, upper_bound}; } else { return std::uniform_int_distribution{lower_bound, upper_bound}; } }(); auto engine = std::default_random_engine{rng}; return dist(engine); } template auto random(T lower_bound, T upper_bound) noexcept -> T { static std::random_device r{}; return random(r(), lower_bound, upper_bound); } template auto random() noexcept -> T { if constexpr (std::is_floating_point::value) { return random(0.0, 1.0); } else if constexpr (std::is_same::value) { // uint16_t because the C++ standard says std::uniform_int_distribution on // 8-bit integer types is undefined behavior for some dumb reason return static_cast(random(0, 1)); } else { return random(std::numeric_limits::min(), std::numeric_limits::max()); } } } // namespace ift630