aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/string/strfry.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/string/strfry.c b/src/string/strfry.c
index b46fb06..aa09d0b 100644
--- a/src/string/strfry.c
+++ b/src/string/strfry.c
@@ -35,12 +35,13 @@
*/
char* strfry(char* anagram)
{
- size_t i, j;
+ size_t i, j, n;
int r;
char t;
if (anagram == NULL)
return NULL;
- for (i = strlen(anagram) - 1; i; i--)
+ n = strlen(anagram);
+ for (i = n - 1; n && i; i--)
{
r = rand();
j = (size_t)((double)r / ((double)RAND_MAX + 1) * (double)i); /* TODO This is not uniformally random. */