From: Yann Duplouy Date: Mon, 18 Nov 2019 12:58:45 +0000 (+0100) Subject: Assertion to force maximum value to be greater or equal to minimum in uniform int X-Git-Tag: v3.25~386^2 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/92b61e41082d8e54e25b87d7d1b772f0447e4802 Assertion to force maximum value to be greater or equal to minimum in uniform int --- diff --git a/src/xbt/random.cpp b/src/xbt/random.cpp index 46f2a0fcb6..63d5353ca1 100644 --- a/src/xbt/random.cpp +++ b/src/xbt/random.cpp @@ -19,6 +19,9 @@ int uniform_int(int min, int max) unsigned long gmax = mt19937_gen.max(); unsigned long grange = gmax - gmin + 1; unsigned long range = max - min + 1; + xbt_assert( + min < max || min == max, + "The maximum value for the uniform integer distribution must be greater than or equal to the minimum value"); xbt_assert(range < grange || range == grange, "The current implementation of the uniform integer distribution does " "not allow range to be higher than mt19937's range"); unsigned long mult = grange / range;