about summary refs log tree commit diff
path: root/Test/V03mathfunc.ztst
diff options
context:
space:
mode:
Diffstat (limited to 'Test/V03mathfunc.ztst')
-rw-r--r--Test/V03mathfunc.ztst32
1 files changed, 32 insertions, 0 deletions
diff --git a/Test/V03mathfunc.ztst b/Test/V03mathfunc.ztst
index d011a1644..069059da4 100644
--- a/Test/V03mathfunc.ztst
+++ b/Test/V03mathfunc.ztst
@@ -104,3 +104,35 @@ F:This test fails if your math library doesn't have erand48().
    print $(( sqrt(-1) ))
 1:Non-negative argument checking for square roots.
 ?(eval):1: math: argument to sqrt out of range
+
+# Simple test that the pseudorandom number generators are producing
+# something that could conceivably be pseudorandom numbers in a
+# linear range.  Not a detailed quantitative verification.
+  integer N=10000 isource ok=1
+  float -F f sum sumsq max max2 av sd
+  typeset -a randoms
+  randoms=('f = RANDOM' 'f = rand48()')
+  zmodload -i zsh/mathfunc
+  for isource in 1 2; do
+    (( sum = sumsq = max = 0 ))
+    repeat $N; do
+      let $randoms[$isource]
+      (( f > max )) && (( max = f ))
+      (( sum += f, sumsq += f * f ))
+    done
+    (( av = sum / N ))
+    (( sd = sqrt((sumsq - N * av * av) / (N-1)) ))
+    (( max2 = 0.5 * max ))
+    if (( av > max2 * 1.1 )) || (( av < max2 * 0.9 )); then
+      print "WARNING: average of random numbers is suspicious.
+  Was testing: $randoms[$isource]"
+      (( ok = 0 ))
+    fi
+    if (( sd < max / 4 )); then
+      print "WARNING: distribution of random numbers is suspicious.
+  Was testing: $randoms[$isource]"
+      (( ok = 0 ))
+    fi
+  done
+  (( ok ))
+0:Test random number generator distributions are not grossly broken