-/* Copyright (c) 2008-2019. The SimGrid Team.
+/* Copyright (c) 2008-2020. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
/* Random number initialization */
srand( (int) (xbt_os_time()*1000) );
- do {
- i = rand()%host_count;
- j = rand()%host_count;
- } while(i==j);
+ /* Take random i and j, with i != j */
+ xbt_assert(host_count > 1);
+ i = rand() % host_count;
+ j = rand() % (host_count - 1);
+ if (j >= i) // '>=' is not a bug: j is uniform on host_count-1 values, and shifted on need to maintain uniform random
+ j++;
const_sg_host_t h1 = hosts[i];
const_sg_host_t h2 = hosts[j];