Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/core/StarStaticRandom.hpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-06-25 20:01:32 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-06-25 20:01:32 +1000
commit13a74602bd4c46149da9949d448387a40b8ebd1c (patch)
tree74c5d7c4f3732155e65e8df454017c5b7d2ca35d /source/core/StarStaticRandom.hpp
parentdf661be1a3623d0a655758095fb08cb953448336 (diff)
Upgrade to C++17
Diffstat (limited to 'source/core/StarStaticRandom.hpp')
-rw-r--r--source/core/StarStaticRandom.hpp22
1 files changed, 19 insertions, 3 deletions
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 <typename T>
+class URBG {
+public:
+ typedef function <T()> Function;
+
+ URBG(Function func) : m_func(func) {};
+
+ typedef T result_type;
+ static constexpr T min() { return std::numeric_limits<T>::min(); };
+ static constexpr T max() { return std::numeric_limits<T>::max(); };
+ T operator()() { return m_func(); };
+private:
+ Function m_func;
+};
+
template <typename Container, typename T, typename... TL>
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<size_t>([&]() {
+ return staticRandomU32Range(0, max - 1, ++mix, d, rest...);
+ }));
}
}