Add function to BaseLibrary class to retrieve random value.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
3dcefebee7
commit
c6ce5fe8a7
|
@ -4,6 +4,7 @@
|
|||
#include <Arbutils/Assert.hpp>
|
||||
#include <Arbutils/Collections/Dictionary.hpp>
|
||||
#include <Arbutils/ConstString.hpp>
|
||||
#include <Arbutils/Random.hpp>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
@ -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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue