From 92b61e41082d8e54e25b87d7d1b772f0447e4802 Mon Sep 17 00:00:00 2001 From: Yann Duplouy Date: Mon, 18 Nov 2019 13:58:45 +0100 Subject: [PATCH] Assertion to force maximum value to be greater or equal to minimum in uniform int --- src/xbt/random.cpp | 3 +++ 1 file changed, 3 insertions(+) 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; -- 2.20.1