From c6ce5fe8a7c630152b4032077447427c37e631c4 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sun, 19 Apr 2020 17:01:33 +0200 Subject: [PATCH] Add function to BaseLibrary class to retrieve random value. --- src/Library/BaseLibrary.hpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Library/BaseLibrary.hpp b/src/Library/BaseLibrary.hpp index 7a66aac..0a635d3 100644 --- a/src/Library/BaseLibrary.hpp +++ b/src/Library/BaseLibrary.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -53,6 +54,17 @@ namespace CreatureLib::Library { } [[nodiscard]] size_t GetCount() const { return _values.Count(); } + + inline const T* GetRandomValue(Arbutils::Random rand = Arbutils::Random()) const { + auto i = rand.Get(_values.Count()); + auto& map = _values.GetStdMap(); + return std::next(std::begin(map), i)->first; + } + inline const T* GetRandomValue(Arbutils::Random* rand) const { + auto i = rand->Get(_values.Count()); + auto& map = _values.GetStdMap(); + return std::next(std::begin(map), i)->first; + } }; }