aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--builtin.c11
2 files changed, 11 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 9daa8cc3..2240218a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,11 @@
* main.c (main): Ignore SIGPIPE. See the comment in the code.
Thanks to Alan Broder for reporting the issue.
+ Unrelated:
+
+ * rand.c (do_rand): Fix computation and loop checking against
+ 1.0 to use do..while.
+
2013-10-16 Arnold D. Robbins <arnold@skeeve.com>
Make -O work again. Turns out that C99 bool variables
diff --git a/builtin.c b/builtin.c
index 740c88b2..4f1914f4 100644
--- a/builtin.c
+++ b/builtin.c
@@ -2432,12 +2432,13 @@ do_rand(int nargs ATTRIBUTE_UNUSED)
* }
*/
- tmprand = 0.5 + ( (random()/RAND_DIVISOR + random()) / RAND_DIVISOR);
+ do {
+ tmprand = 0.5 + ( (random()/RAND_DIVISOR + random())
+ / RAND_DIVISOR);
+ tmprand -= 0.5;
+ } while (tmprand == 1.0);
- while (tmprand == 1.0)
- tmprand = 0.5 + ( (random()/RAND_DIVISOR + random()) / RAND_DIVISOR);
-
- return make_number((AWKNUM) (tmprand - 0.5));
+ return make_number((AWKNUM) tmprand);
}
/* do_srand --- seed the random number generator */