aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--builtin.c10
2 files changed, 15 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 92545988..f3d950b2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2014-04-20 Arnold D. Robbins <arnold@skeeve.com>
+
+ * builtin.c (do_rand): Make calls to random() in predictable
+ order to avoid order of evaluation differences amongst compilers.
+ Thanks to Anders Magnusson <ragge@ludd.ltu.se> (of the PCC team)
+ for the suggestion.
+
2014-04-18 Arnold D. Robbins <arnold@skeeve.com>
* configure.ac: Change adding of -export-dynamic for GCC to be
diff --git a/builtin.c b/builtin.c
index 875b3e5c..3464dc21 100644
--- a/builtin.c
+++ b/builtin.c
@@ -2454,8 +2454,14 @@ do_rand(int nargs ATTRIBUTE_UNUSED)
*/
do {
- tmprand = 0.5 + ( (random()/RAND_DIVISOR + random())
- / RAND_DIVISOR);
+ long d1, d2;
+ /*
+ * Do the calls in predictable order to avoid
+ * compiler differences in order of evaluation.
+ */
+ d1 = random();
+ d2 = random();
+ tmprand = 0.5 + ( (d1/RAND_DIVISOR + d2) / RAND_DIVISOR );
tmprand -= 0.5;
} while (tmprand == 1.0);