aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-03-01 23:18:29 +0100
committerMattias Andrée <maandree@kth.se>2016-03-01 23:18:29 +0100
commit03954f405c7bfe6218e2a0d2f2a82605dc073a06 (patch)
treed9cfe7d179bff5f00f6cd32d7bb2295f1feac741
parentstrfry: non-uniform random number generation (diff)
downloadslibc-03954f405c7bfe6218e2a0d2f2a82605dc073a06.tar.gz
slibc-03954f405c7bfe6218e2a0d2f2a82605dc073a06.tar.bz2
slibc-03954f405c7bfe6218e2a0d2f2a82605dc073a06.tar.xz
strfry: use Durstenfeld's algorithm instead of Satallo's algorithm
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--src/string/strfry.c4
1 files 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 <stdlib.h>
-/* 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. */