diff options
author | Mattias Andrée <maandree@kth.se> | 2016-03-30 21:34:35 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2016-03-30 21:34:35 +0200 |
commit | 7b49953b007f99fad8a5d3c7661b120ce96fa074 (patch) | |
tree | b0569d9911f50efcb909c688867a93b54e863351 /src | |
parent | strfry: fix random int range boundary, document that srand should have been called, support huge strings, and use uniform random (diff) | |
download | slibc-7b49953b007f99fad8a5d3c7661b120ce96fa074.tar.gz slibc-7b49953b007f99fad8a5d3c7661b120ce96fa074.tar.bz2 slibc-7b49953b007f99fad8a5d3c7661b120ce96fa074.tar.xz |
strfry: reset n to max when the do..while loop resets
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src')
-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 5aec420..cf6324b 100644 --- a/src/string/strfry.c +++ b/src/string/strfry.c @@ -37,11 +37,11 @@ static size_t uniform_random_zu(size_t max) { - size_t n = max, r = 0, mask = max, s = 1; + size_t n, r = 0, mask = max, s = 1; while (((mask + 1) & ~mask) != mask + 1) mask |= mask >> s++; do - for (; n; n >>= BITS) + for (n = max; n; n >>= BITS) { b = rand(); b /= (double)RAND_MAX + 1; |