summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--Test/V03mathfunc.ztst32
2 files changed, 37 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 1110e1c2a..a13b21812 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2004-12-07 Peter Stephenson <pws@csr.com>
+
+ * 20606: Test/V03mathfunc.ztst: simple verification of
+ pseudorandom numbers.
+
2004-12-06 Doug Kearns <djkea2@gus.gscit.monash.edu.au>
* 20601: Completion/Unix/Command/_python: update python completion for
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