Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
CommWaitTransition mailbox is now valid
[simgrid.git] / src / xbt / random.cpp
index 088545eb5f1fdff657bcba2fcaadb696502ffbfd..449207c9bb48a95d5276fcb3834e60467253647b 100644 (file)
@@ -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<unsigned>(max) - static_cast<unsigned>(min);
   xbt_assert(min <= max,
              "The minimum value for the uniform integer distribution must not be greater than the maximum value");