diff options
author | Mattias Andrée <maandree@kth.se> | 2016-03-01 23:18:29 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2016-03-01 23:18:29 +0100 |
commit | 03954f405c7bfe6218e2a0d2f2a82605dc073a06 (patch) | |
tree | d9cfe7d179bff5f00f6cd32d7bb2295f1feac741 | |
parent | strfry: non-uniform random number generation (diff) | |
download | slibc-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>
Diffstat (limited to '')
-rw-r--r-- | src/string/strfry.c | 4 |
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. */ |