From a0ca839420118a77a19a8ab05d08f58a076edd17 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Thu, 17 Oct 2013 22:08:24 +0300 Subject: Additional fix in do_rand. --- builtin.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'builtin.c') 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 */ -- cgit v1.2.3