diff --git a/src/rnd.cpp b/src/rnd.cpp index 9cee4098..3d9c44a2 100644 --- a/src/rnd.cpp +++ b/src/rnd.cpp @@ -20,6 +20,8 @@ #include "rapidhash/rapidhash.h" +#include + #include @@ -57,6 +59,7 @@ RND::rand64(void) u64 RND::rand64(cu64 max_) { + assert(max_ > 0); return (RND::rand64() % max_); } @@ -64,5 +67,6 @@ u64 RND::rand64(cu64 min_, cu64 max_) { + assert(max_ > min_); return (min_ + (RND::rand64() % (max_ - min_))); } diff --git a/src/rnd.hpp b/src/rnd.hpp index 0cedbfc0..af90fb5c 100644 --- a/src/rnd.hpp +++ b/src/rnd.hpp @@ -20,7 +20,7 @@ #include "base_types.h" -#include +#include class RND { @@ -38,14 +38,10 @@ public: void shrink_to_rand_elem(std::vector &v_) { - static std::mt19937 gen(std::random_device{}()); - if(v_.size() <= 1) return; - std::uniform_int_distribution<> dist(0,(v_.size() - 1)); - - std::swap(v_[0],v_[dist(gen)]); + std::swap(v_[0],v_[RND::rand64(v_.size())]); v_.resize(1); }