1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-06-08 08:16:05 +02:00

20606: simple verification of pseudorandom numbers

This commit is contained in:
Peter Stephenson 2004-12-07 12:07:54 +00:00
parent 48582a9a60
commit ddc186f3f6
2 changed files with 37 additions and 0 deletions

View File

@ -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

View File

@ -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