From 13a74602bd4c46149da9949d448387a40b8ebd1c Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Sun, 25 Jun 2023 20:01:32 +1000 Subject: Upgrade to C++17 --- source/core/StarStaticRandom.hpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'source/core/StarStaticRandom.hpp') diff --git a/source/core/StarStaticRandom.hpp b/source/core/StarStaticRandom.hpp index 97cfdef..b55b411 100644 --- a/source/core/StarStaticRandom.hpp +++ b/source/core/StarStaticRandom.hpp @@ -118,12 +118,28 @@ typename Container::value_type staticRandomValueFrom(Container const& container, } } +template +class URBG { +public: + typedef function Function; + + URBG(Function func) : m_func(func) {}; + + typedef T result_type; + static constexpr T min() { return std::numeric_limits::min(); }; + static constexpr T max() { return std::numeric_limits::max(); }; + T operator()() { return m_func(); }; +private: + Function m_func; +}; + template void staticRandomShuffle(Container& container, T const& d, TL const&... rest) { int mix = 0; - std::random_shuffle(container.begin(), - container.end(), - [&](size_t max) { return staticRandomU32Range(0, max - 1, ++mix, d, rest...); }); + size_t max = container.size(); + std::shuffle(container.begin(), container.end(), URBG([&]() { + return staticRandomU32Range(0, max - 1, ++mix, d, rest...); + })); } } -- cgit v1.2.3