about summary refs log tree commit diff
path: root/Test/V03mathfunc.ztst
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2004-12-07 12:07:54 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2004-12-07 12:07:54 +0000
commitddc186f3f69ee72f97d222eba424667164f73526 (patch)
treed2870c1d78c0d923de59f452f4f6f7c17d2305d1 /Test/V03mathfunc.ztst
parent48582a9a60b6d56758117827d36cf9642391e260 (diff)
downloadzsh-ddc186f3f69ee72f97d222eba424667164f73526.tar.gz
zsh-ddc186f3f69ee72f97d222eba424667164f73526.tar.xz
zsh-ddc186f3f69ee72f97d222eba424667164f73526.zip
20606: simple verification of pseudorandom numbers
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