diff options
Diffstat (limited to 'test/random-generator.test')
-rwxr-xr-x | test/random-generator.test | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/test/random-generator.test b/test/random-generator.test new file mode 100755 index 00000000..88c9d31d --- /dev/null +++ b/test/random-generator.test @@ -0,0 +1,68 @@ +#! /bin/bash +# This script tests: pgmnoise +# Also requires: + +echo "Test 1: Should produce:" + +echo "P2" +echo "12 1" +echo "1023" +echo "720 296 192 858 101 57 298 629 804 1019 64 617" +echo "Above output is for Mersenne Twister" + +# GNU libc rand(): 593 252 207 990 507 824 961 805 559 110 167 172 +# MAC OS rand(): 9 782 60 418 364 654 670 172 1022 515 593 903 + +pgmnoise -maxval=1023 -randomseed=3791 -plain 12 1 + +echo +echo "Test 2: Mersenne Twister random number generator" +echo "Should produce:" + +echo "3499211612 581869302 3890346734 3586334585 545404204" +echo "4161255391 3922919429 949333985 2715962298 1323567403" +echo " ... " +echo " 297480282 1101405687 1473439254 2634793792 1341017984" +echo " Total 1000 integers, 200 lines" +echo + +# Use perl to avoid mawk limitation +# (cannot convert 32 bit integers) + +perlPgmProcessorProgram=' + if (($#F+1) == 10) { + for (my $i = 0; $i <= 9; $i += 2) { + my $r = $F[$i + 1] * 65536 + $F[$i]; + printf "%10u ", $r; + } + print ""; + } +' + +pgmnoise -randomseed=5489 -plain -maxval=65535 10 200 | tee /tmp/z | + perl -walne "$perlPgmProcessorProgram" + +# Method to generate output for Test 2 from original +# Mersenne Twister source code + +# Download Mersenne Twister code. See lib/util/randmersenne.c for URL. +# Edit mt19937ar.c: +# In function main() at bottom of file, replace +# init_by_array(init, length); +# with +# init_genrand(5489UL); +# +# We need only the output of genrand_int32(). +# Remove the second loop which produces double-precision floating point +# random numbers with genrand_real2(). +# +# Compile: gcc mt19937ar.c -o mt1000 +# Execute: ./mt1000 + +# 1000 may seem like a large number of samples but there is a reason +# for this. The generator produces random integers in batches of 624. +# The number of samples must be larger than 624 to ensure proper +# generation in batches after the first. + + + |