diff --git a/src/common/random.hpp b/src/common/random.hpp index 1ed4b91db7..35ef736629 100644 --- a/src/common/random.hpp +++ b/src/common/random.hpp @@ -15,12 +15,15 @@ inline std::mt19937 generator = std::mt19937(device()); int32 rnd(void);// [0, SINT32_MAX] /* - * Generates a random number in the interval [min, max] + * Generates a random number in the interval [a, b] * @return random number */ template -typename std::enable_if::value, T>::type rnd_value(T min, T max) { - std::uniform_int_distribution dist(min, max); +typename std::enable_if::value, T>::type rnd_value(T a, T b) { + if (a > b) { + std::swap(a, b); + } + std::uniform_int_distribution dist(a, b); return dist(generator); }