diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common/shuffle.c | 17 | ||||
-rw-r--r-- | src/core/core.c | 7 |
2 files changed, 21 insertions, 3 deletions
diff --git a/src/common/shuffle.c b/src/common/shuffle.c index 6b20866..e2e0a3d 100644 --- a/src/common/shuffle.c +++ b/src/common/shuffle.c @@ -53,6 +53,14 @@ void shuffle(void *base, size_t nmemb, size_t size) * Application de l'algorithme Fisher-Yates. * * Cf. https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle + * + * En version hors-ligne, cela donne : + * + * -- To shuffle an array a of n elements (indices 0..n-1): + * for i from 0 to nā2 do + * j ā random integer such that i ā¤ j < n + * exchange a[i] and a[j] + * */ if (nmemb > 1) @@ -65,9 +73,12 @@ void shuffle(void *base, size_t nmemb, size_t size) { j = i + rand() % (nmemb - i); - memcpy(tmp, list + i * size, size); - memcpy(list + i * size, list + j * size, size); - memcpy(list + j * size, tmp, size); + if (j != i) + { + memcpy(tmp, list + i * size, size); + memcpy(list + i * size, list + j * size, size); + memcpy(list + j * size, tmp, size); + } } diff --git a/src/core/core.c b/src/core/core.c index ec7b0fc..b949e0a 100644 --- a/src/core/core.c +++ b/src/core/core.c @@ -24,6 +24,11 @@ #include "core.h" +#include <stdlib.h> +#include <time.h> +#include <unistd.h> + + #include <config.h> @@ -62,6 +67,8 @@ bool load_all_basic_components(void) { result = true; + srand(time(NULL) + getpid()); + add_pixmap_directory(PACKAGE_DATA_DIR); add_pixmap_directory(PACKAGE_SOURCE_DIR G_DIR_SEPARATOR_S "pixmaps"); |