From 03954f405c7bfe6218e2a0d2f2a82605dc073a06 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 1 Mar 2016 23:18:29 +0100 Subject: strfry: use Durstenfeld's algorithm instead of Satallo's algorithm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/string/strfry.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/string/strfry.c b/src/string/strfry.c index 77a771f..f8b5b2c 100644 --- a/src/string/strfry.c +++ b/src/string/strfry.c @@ -19,7 +19,7 @@ #include -/* Sattolo Cycles. */ +/* Durstenfeld's algorithm. */ @@ -40,7 +40,7 @@ char* strfry(char* anagram) char t; if (anagram == NULL) return NULL; - for (i = strlen(anagram); --i;) + for (i = strlen(anagram); i; i--) { r = rand(); j = (size_t)((double)r / ((double)RAND_MAX + 1) * (double)i); /* TODO This is not uniformally random. */ -- cgit v1.2.3-70-g09d2