Fixed issue with Valgrind.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
6f60cd7c96
commit
460f9308a0
|
@ -9,7 +9,7 @@ namespace Arbutils {
|
|||
|
||||
template <class RandomT> class BaseRandom {
|
||||
private:
|
||||
uint32_t _seed;
|
||||
uint_fast32_t _seed;
|
||||
RandomT _rng;
|
||||
std::uniform_real_distribution<double> _distribution;
|
||||
|
||||
|
@ -20,21 +20,17 @@ namespace Arbutils {
|
|||
.count()),
|
||||
_rng(_seed), _distribution(0.0, 1.0) {}
|
||||
|
||||
explicit inline constexpr BaseRandom(uint64_t seed) noexcept
|
||||
explicit inline constexpr BaseRandom(uint_fast32_t seed) noexcept
|
||||
: _seed(seed), _rng(seed), _distribution(0.0, 1.0){};
|
||||
|
||||
/// Gets a random float between 0.0 and 1.0.
|
||||
[[nodiscard]] inline constexpr float GetFloat() noexcept {
|
||||
return static_cast<float>(GetDouble());
|
||||
}
|
||||
[[nodiscard]] inline constexpr float GetFloat() noexcept { return static_cast<float>(GetDouble()); }
|
||||
|
||||
/// Gets a random double between 0.0 and 1.0.
|
||||
[[nodiscard]] inline constexpr double GetDouble() noexcept {
|
||||
return (double) _distribution(_rng);
|
||||
}
|
||||
[[nodiscard]] inline constexpr double GetDouble() noexcept { return _distribution(_rng); }
|
||||
|
||||
/// Gets a random 32 bit integer
|
||||
[[nodiscard]] inline constexpr int32_t Get() noexcept { return (int32_t)_rng(); }
|
||||
[[nodiscard]] inline constexpr int32_t Get() noexcept { return static_cast<int32_t>(_rng()); }
|
||||
|
||||
/// Gets a random 32 bit integer between 0, and given max parameter.
|
||||
/// \param max The exclusive max value the random value should be.
|
||||
|
@ -52,9 +48,7 @@ namespace Arbutils {
|
|||
}
|
||||
|
||||
/// Gets a random 32 bit unsigned integer between 0 and max unsigned int.
|
||||
[[nodiscard]] inline constexpr uint32_t GetUnsigned() noexcept {
|
||||
return _rng();
|
||||
}
|
||||
[[nodiscard]] inline constexpr uint32_t GetUnsigned() noexcept { return _rng(); }
|
||||
|
||||
/// Gets a random 32 bit unsigned integer between 0, and given max parameter.
|
||||
/// \param max The exclusive max value the random value should be.
|
||||
|
@ -71,13 +65,13 @@ namespace Arbutils {
|
|||
return distribution(_rng);
|
||||
}
|
||||
|
||||
[[nodiscard]] inline constexpr uint32_t GetSeed() const noexcept { return _seed; }
|
||||
[[nodiscard]] inline constexpr uint_fast32_t GetSeed() const noexcept { return _seed; }
|
||||
};
|
||||
|
||||
class Random : public BaseRandom<std::mt19937> {
|
||||
public:
|
||||
constexpr Random() : BaseRandom() {}
|
||||
constexpr Random(int32_t seed) : BaseRandom(seed) {}
|
||||
constexpr Random(uint_fast32_t seed) : BaseRandom(seed) {}
|
||||
};
|
||||
}
|
||||
#endif // ARBUTILS_RANDOM_HPP
|
||||
|
|
|
@ -93,7 +93,7 @@ TEST_CASE("Random distribution (max 0, min 2)", "[Utilities]") {
|
|||
|
||||
TEST_CASE("Random distribution (max 0, min 3)", "[Utilities]") {
|
||||
auto rand = Arbutils::Random(10);
|
||||
const int size = 500000;
|
||||
const size_t size = 100000;
|
||||
int arr[size];
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
arr[i] = rand.Get(0, 3);
|
||||
|
|
Loading…
Reference in New Issue