X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/0ffe6c466e437ebbda9be47bbd77d3775623a2d7..f9b13d923d31bb0336aeeaab6d5b7ba33812f3f7:/src/xbt/random.cpp diff --git a/src/xbt/random.cpp b/src/xbt/random.cpp index 088545eb5f..449207c9bb 100644 --- a/src/xbt/random.cpp +++ b/src/xbt/random.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2019-2021. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2019-2022. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -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");