diff --git a/src/Random.hpp b/src/Random.hpp index ac40675..09b9ac2 100644 --- a/src/Random.hpp +++ b/src/Random.hpp @@ -4,6 +4,7 @@ #include #include #include +#include "Assert.hpp" namespace Arbutils { @@ -34,7 +35,8 @@ namespace Arbutils { /// Gets a random 32 bit integer between 0, and given max parameter. /// \param max The exclusive max value the random value should be. - [[nodiscard]] inline int32_t Get(int32_t max) noexcept { + [[nodiscard]] inline int32_t Get(int32_t max) { + Assert(max > 0); std::uniform_int_distribution distribution(0, max - 1); return distribution(_rng); } @@ -42,7 +44,8 @@ namespace Arbutils { /// Gets a random 32 bit integer between given min and max parameters. /// \param min The inclusive min value the random value should be. /// \param max The exclusive max value the random value should be. - [[nodiscard]] inline int32_t Get(int32_t min, int32_t max) noexcept { + [[nodiscard]] inline int32_t Get(int32_t min, int32_t max) { + Assert(max > min); std::uniform_int_distribution distribution(min, max - 1); return distribution(_rng); } @@ -60,7 +63,8 @@ namespace Arbutils { /// Gets a random 32 bit unsigned integer between given min and max parameters. /// \param min The inclusive min value the random value should be. /// \param max The exclusive max value the random value should be. - [[nodiscard]] inline uint32_t GetUnsigned(uint32_t min, uint32_t max) noexcept { + [[nodiscard]] inline uint32_t GetUnsigned(uint32_t min, uint32_t max) { + Assert(max > min); std::uniform_int_distribution distribution(min, max - 1); return distribution(_rng); } @@ -71,7 +75,7 @@ namespace Arbutils { class Random : public BaseRandom { public: constexpr Random() : BaseRandom() {} - constexpr Random(uint_fast32_t seed) : BaseRandom(seed) {} + explicit constexpr Random(uint_fast32_t seed) : BaseRandom(seed) {} }; } #endif // ARBUTILS_RANDOM_HPP