diff options
author | Shauren <shauren.trinity@gmail.com> | 2017-03-21 21:04:01 +0100 |
---|---|---|
committer | ariel- <ariel-@users.noreply.github.com> | 2017-06-03 02:20:50 -0300 |
commit | ff39c27104634c9f1d37a0625eb78461e34c77a0 (patch) | |
tree | 413970e966590b0575fc7ad97f1c9a339cec4d7c /src/common/Utilities/Random.cpp | |
parent | d6fbe994325ea6b23d144562245e749115700996 (diff) |
Core/Utils: Changed all Trinity::Containers utilities to work on all container types (including arrays where it makes sense)
* Added MapGetValuePtr to allow writing `if (Val* v = MapGetValuePtr(map, key))`
* Added utility IteratorPair class with begin/end methods and MapEqualRange for use in range for syntax with multimaps
(cherry picked from commit a1e3b54e076bf0361d23ace53703a4e501354d7c)
Diffstat (limited to 'src/common/Utilities/Random.cpp')
-rw-r--r-- | src/common/Utilities/Random.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/common/Utilities/Random.cpp b/src/common/Utilities/Random.cpp index defe43d82c2..3a0cdedcf4b 100644 --- a/src/common/Utilities/Random.cpp +++ b/src/common/Utilities/Random.cpp @@ -20,8 +20,10 @@ #include "Errors.h" #include "SFMT.h" #include <boost/thread/tss.hpp> +#include <random> static boost::thread_specific_ptr<SFMTRand> sfmtRand; +static SFMTEngine engine; static SFMTRand* GetRng() { @@ -84,8 +86,13 @@ double rand_chance() return GetRng()->Random() * 100.0; } +uint32 urandweighted(size_t count, double const* chances) +{ + std::discrete_distribution<uint32> dd(chances, chances + count); + return dd(SFMTEngine::Instance()); +} + SFMTEngine& SFMTEngine::Instance() { - static SFMTEngine engine; return engine; } |