From 6750837854d8e0701ca7a112e6631fc10889b245 Mon Sep 17 00:00:00 2001 From: Vincent Stumpf Date: Sun, 24 Dec 2023 15:42:02 -0800 Subject: [PATCH] Let rnd_value callers not care about order (#8046) --- src/common/random.hpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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); }