From b052928e93b3f538f2958c92677ef1e72672802b Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Sat, 27 Mar 2021 23:38:19 +0100 Subject: [PATCH] Add explaining comment. --- src/xbt/random.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/xbt/random.cpp b/src/xbt/random.cpp index 088545eb5f..ed9670050e 100644 --- a/src/xbt/random.cpp +++ b/src/xbt/random.cpp @@ -65,6 +65,8 @@ double StdRandom::normal(double mean, double sd) int XbtRandom::uniform_int(int min, int max) { + // The casts to unsigned are here to ensure that the value of range is correctly calculated, even when greater than + // INT_MAX. See the corresponding unit tests for examples. unsigned long range = static_cast(max) - static_cast(min); xbt_assert(min <= max, "The minimum value for the uniform integer distribution must not be greater than the maximum value"); -- 2.20.1