From ddc186f3f69ee72f97d222eba424667164f73526 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 7 Dec 2004 12:07:54 +0000 Subject: 20606: simple verification of pseudorandom numbers --- Test/V03mathfunc.ztst | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'Test') 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 -- cgit 1.4.1