NOTE Most of the tests in DIEHARD return a p-value, which should be uniform on [0,1) if the input file contains truly independent random bits. Those p-values are obtained by p=1-F(X), where F is the assumed distribution of the sample random variable X---often normal. But that assumed F is often just an asymptotic approximation, for which the fit will be worst in the tails. Thus you should not be surprised with occasion- al p-values near 0 or 1, such as .0012 or .9983. When a bit stream really FAILS BIG, you will get p`s of 0 or 1 to six or more places. By all means, do not, as a Statistician might, think that a p < .025 or p> .975 means that the RNG has "failed the test at the .05 level". Such p`s happen among the hundreds that DIEHARD produces, even with good RNGs. So keep in mind that "p happens" Enter the name of the file to be tested. This must be a form="unformatted",access="direct" binary file of about 10-12 million bytes. Enter file name: HERE ARE YOUR CHOICES: 1 Birthday Spacings 2 Overlapping Permutations 3 Ranks of 31x31 and 32x32 matrices 4 Ranks of 6x8 Matrices 5 Monkey Tests on 20-bit Words 6 Monkey Tests OPSO,OQSO,DNA 7 Count the 1`s in a Stream of Bytes 8 Count the 1`s in Specific Bytes 9 Parking Lot Test 10 Minimum Distance Test 11 Random Spheres Test 12 The Sqeeze Test 13 Overlapping Sums Test 14 Runs Test 15 The Craps Test 16 All of the above To choose any particular tests, enter corresponding numbers. Enter 16 for all tests. If you want to perform all but a few tests, enter corresponding numbers preceded by "-" sign. Tests are executed in the order they are entered. Enter your choices. |-------------------------------------------------------------| | This is the BIRTHDAY SPACINGS TEST | |Choose m birthdays in a "year" of n days. List the spacings | |between the birthdays. Let j be the number of values that | |occur more than once in that list, then j is asymptotically | |Poisson distributed with mean m^3/(4n). Experience shows n | |must be quite large, say n>=2^18, for comparing the results | |to the Poisson distribution with that mean. This test uses | |n=2^24 and m=2^10, so that the underlying distribution for j | |is taken to be Poisson with lambda=2^30/(2^26)=16. A sample | |of 200 j''s is taken, and a chi-square goodness of fit test | |provides a p value. The first test uses bits 1-24 (counting | |from the left) from integers in the specified file. Then the| |file is closed and reopened, then bits 2-25 of the same inte-| |gers are used to provide birthdays, and so on to bits 9-32. | |Each set of bits provides a p-value, and the nine p-values | |provide a sample for a KSTEST. | |------------------------------------------------------------ | RESULTS OF BIRTHDAY SPACINGS TEST FOR ./rand.data (no_bdays=1024, no_days/yr=2^24, lambda=16.00, sample size=500) Bits used mean chisqr p-value 1 to 24 15.67 9.5718 0.920600 2 to 25 15.65 19.8073 0.284203 3 to 26 16.18 19.7658 0.286381 4 to 27 15.70 29.3881 0.031111 5 to 28 16.07 18.6400 0.349581 6 to 29 15.82 21.0932 0.222150 7 to 30 16.03 10.1481 0.897286 8 to 31 15.56 22.7475 0.157652 9 to 32 15.83 23.4006 0.136657 degree of freedoms is: 17 --------------------------------------------------------------- p-value for KStest on those 9 p-values: 0.149681 |-------------------------------------------------------------| | THE OVERLAPPING 5-PERMUTATION TEST | |This is the OPERM5 test. It looks at a sequence of one mill-| |ion 32-bit random integers. Each set of five consecutive | |integers can be in one of 120 states, for the 5! possible or-| |derings of five numbers. Thus the 5th, 6th, 7th,...numbers | |each provide a state. As many thousands of state transitions | |are observed, cumulative counts are made of the number of | |occurences of each state. Then the quadratic form in the | |weak inverse of the 120x120 covariance matrix yields a test | |equivalent to the likelihood ratio test that the 120 cell | |counts came from the specified (asymptotically) normal dis- | |tribution with the specified 120x120 covariance matrix (with | |rank 99). This version uses 1,000,000 integers, twice. | |-------------------------------------------------------------| OPERM5 test for file (For samples of 1,000,000 consecutive 5-tuples) sample 1 chisquare=96.172922 with df=99; p-value= 0.561724 _______________________________________________________________ sample 2 chisquare=105.309613 with df=99; p-value= 0.313352 _______________________________________________________________ |-------------------------------------------------------------| |This is the BINARY RANK TEST for 31x31 matrices. The leftmost| |31 bits of 31 random integers from the test sequence are used| |to form a 31x31 binary matrix over the field {0,1}. The rank | |is determined. That rank can be from 0 to 31, but ranks< 28 | |are rare, and their counts are pooled with those for rank 28.| |Ranks are found for 40,000 such random matrices and a chisqu-| |are test is performed on counts for ranks 31,30,28 and <=28. | |-------------------------------------------------------------| Rank test for binary matrices (31x31) from ./rand.data RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=28 208 211.4 0.055 0.055 r=29 5168 5134.0 0.225 0.280 r=30 23114 23103.0 0.005 0.285 r=31 11510 11551.5 0.149 0.435 chi-square = 0.435 with df = 3; p-value = 0.933 -------------------------------------------------------------- |-------------------------------------------------------------| |This is the BINARY RANK TEST for 32x32 matrices. A random 32x| |32 binary matrix is formed, each row a 32-bit random integer.| |The rank is determined. That rank can be from 0 to 32, ranks | |less than 29 are rare, and their counts are pooled with those| |for rank 29. Ranks are found for 40,000 such random matrices| |and a chisquare test is performed on counts for ranks 32,31,| |30 and <=29. | |-------------------------------------------------------------| Rank test for binary matrices (32x32) from ./rand.data RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=29 223 211.4 0.634 0.634 r=30 5116 5134.0 0.063 0.698 r=31 23222 23103.0 0.612 1.310 r=32 11439 11551.5 1.096 2.406 chi-square = 2.406 with df = 3; p-value = 0.492 -------------------------------------------------------------- |-------------------------------------------------------------| |This is the BINARY RANK TEST for 6x8 matrices. From each of | |six random 32-bit integers from the generator under test, a | |specified byte is chosen, and the resulting six bytes form a | |6x8 binary matrix whose rank is determined. That rank can be| |from 0 to 6, but ranks 0,1,2,3 are rare; their counts are | |pooled with those for rank 4. Ranks are found for 100,000 | |random matrices, and a chi-square test is performed on | |counts for ranks 6,5 and (0,...,4) (pooled together). | |-------------------------------------------------------------| Rank test for binary matrices (6x8) from ./rand.data bits 1 to 8 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 933 944.3 0.135 0.135 r=5 21660 21743.9 0.324 0.459 r=6 77407 77311.8 0.117 0.576 chi-square = 0.576 with df = 2; p-value = 0.750 -------------------------------------------------------------- bits 2 to 9 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 931 944.3 0.187 0.187 r=5 21574 21743.9 1.328 1.515 r=6 77495 77311.8 0.434 1.949 chi-square = 1.949 with df = 2; p-value = 0.377 -------------------------------------------------------------- bits 3 to 10 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 961 944.3 0.295 0.295 r=5 21592 21743.9 1.061 1.356 r=6 77447 77311.8 0.236 1.593 chi-square = 1.593 with df = 2; p-value = 0.451 -------------------------------------------------------------- bits 4 to 11 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 922 944.3 0.527 0.527 r=5 21907 21743.9 1.223 1.750 r=6 77171 77311.8 0.256 2.006 chi-square = 2.006 with df = 2; p-value = 0.367 -------------------------------------------------------------- bits 5 to 12 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 920 944.3 0.625 0.625 r=5 21932 21743.9 1.627 2.253 r=6 77148 77311.8 0.347 2.600 chi-square = 2.600 with df = 2; p-value = 0.273 -------------------------------------------------------------- bits 6 to 13 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 914 944.3 0.972 0.972 r=5 21643 21743.9 0.468 1.440 r=6 77443 77311.8 0.223 1.663 chi-square = 1.663 with df = 2; p-value = 0.435 -------------------------------------------------------------- bits 7 to 14 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 909 944.3 1.320 1.320 r=5 21754 21743.9 0.005 1.324 r=6 77337 77311.8 0.008 1.332 chi-square = 1.332 with df = 2; p-value = 0.514 -------------------------------------------------------------- bits 8 to 15 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 926 944.3 0.355 0.355 r=5 21780 21743.9 0.060 0.415 r=6 77294 77311.8 0.004 0.419 chi-square = 0.419 with df = 2; p-value = 0.811 -------------------------------------------------------------- bits 9 to 16 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 943 944.3 0.002 0.002 r=5 21809 21743.9 0.195 0.197 r=6 77248 77311.8 0.053 0.249 chi-square = 0.249 with df = 2; p-value = 0.883 -------------------------------------------------------------- bits 10 to 17 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 991 944.3 2.310 2.310 r=5 21630 21743.9 0.597 2.906 r=6 77379 77311.8 0.058 2.965 chi-square = 2.965 with df = 2; p-value = 0.227 -------------------------------------------------------------- bits 11 to 18 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 969 944.3 0.646 0.646 r=5 21825 21743.9 0.302 0.949 r=6 77206 77311.8 0.145 1.093 chi-square = 1.093 with df = 2; p-value = 0.579 -------------------------------------------------------------- bits 12 to 19 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 914 944.3 0.972 0.972 r=5 21740 21743.9 0.001 0.973 r=6 77346 77311.8 0.015 0.988 chi-square = 0.988 with df = 2; p-value = 0.610 -------------------------------------------------------------- bits 13 to 20 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 936 944.3 0.073 0.073 r=5 21789 21743.9 0.094 0.166 r=6 77275 77311.8 0.018 0.184 chi-square = 0.184 with df = 2; p-value = 0.912 -------------------------------------------------------------- bits 14 to 21 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 927 944.3 0.317 0.317 r=5 21852 21743.9 0.537 0.854 r=6 77221 77311.8 0.107 0.961 chi-square = 0.961 with df = 2; p-value = 0.618 -------------------------------------------------------------- bits 15 to 22 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 945 944.3 0.001 0.001 r=5 21616 21743.9 0.752 0.753 r=6 77439 77311.8 0.209 0.962 chi-square = 0.962 with df = 2; p-value = 0.618 -------------------------------------------------------------- bits 16 to 23 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 916 944.3 0.848 0.848 r=5 21738 21743.9 0.002 0.850 r=6 77346 77311.8 0.015 0.865 chi-square = 0.865 with df = 2; p-value = 0.649 -------------------------------------------------------------- bits 17 to 24 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 970 944.3 0.699 0.699 r=5 21599 21743.9 0.966 1.665 r=6 77431 77311.8 0.184 1.849 chi-square = 1.849 with df = 2; p-value = 0.397 -------------------------------------------------------------- bits 18 to 25 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 908 944.3 1.395 1.395 r=5 21716 21743.9 0.036 1.431 r=6 77376 77311.8 0.053 1.485 chi-square = 1.485 with df = 2; p-value = 0.476 -------------------------------------------------------------- bits 19 to 26 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 918 944.3 0.732 0.732 r=5 21867 21743.9 0.697 1.429 r=6 77215 77311.8 0.121 1.551 chi-square = 1.551 with df = 2; p-value = 0.461 -------------------------------------------------------------- bits 20 to 27 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 983 944.3 1.586 1.586 r=5 21934 21743.9 1.662 3.248 r=6 77083 77311.8 0.677 3.925 chi-square = 3.925 with df = 2; p-value = 0.140 -------------------------------------------------------------- bits 21 to 28 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 930 944.3 0.217 0.217 r=5 21866 21743.9 0.686 0.902 r=6 77204 77311.8 0.150 1.052 chi-square = 1.052 with df = 2; p-value = 0.591 -------------------------------------------------------------- bits 22 to 29 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 927 944.3 0.317 0.317 r=5 21714 21743.9 0.041 0.358 r=6 77359 77311.8 0.029 0.387 chi-square = 0.387 with df = 2; p-value = 0.824 -------------------------------------------------------------- bits 23 to 30 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 974 944.3 0.934 0.934 r=5 21879 21743.9 0.839 1.774 r=6 77147 77311.8 0.351 2.125 chi-square = 2.125 with df = 2; p-value = 0.346 -------------------------------------------------------------- bits 24 to 31 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 935 944.3 0.092 0.092 r=5 21916 21743.9 1.362 1.454 r=6 77149 77311.8 0.343 1.797 chi-square = 1.797 with df = 2; p-value = 0.407 -------------------------------------------------------------- bits 25 to 32 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 875 944.3 5.086 5.086 r=5 21866 21743.9 0.686 5.771 r=6 77259 77311.8 0.036 5.807 chi-square = 5.807 with df = 2; p-value = 0.055 -------------------------------------------------------------- TEST SUMMARY, 25 tests on 100,000 random 6x8 matrices These should be 25 uniform [0,1] random variates: 0.749694 0.377384 0.450921 0.366694 0.272592 0.435372 0.513632 0.811121 0.882786 0.227117 0.578872 0.610159 0.912099 0.618472 0.618128 0.648930 0.396762 0.476036 0.460565 0.140497 0.590816 0.824121 0.345622 0.407270 0.054818 The KS test for those 25 supposed UNI's yields KS p-value = 0.298025 |-------------------------------------------------------------| | THE BITSTREAM TEST | |The file under test is viewed as a stream of bits. Call them | |b1,b2,... . Consider an alphabet with two "letters", 0 and 1| |and think of the stream of bits as a succession of 20-letter | |"words", overlapping. Thus the first word is b1b2...b20, the| |second is b2b3...b21, and so on. The bitstream test counts | |the number of missing 20-letter (20-bit) words in a string of| |2^21 overlapping 20-letter words. There are 2^20 possible 20| |letter words. For a truly random string of 2^21+19 bits, the| |number of missing words j should be (very close to) normally | |distributed with mean 141,909 and sigma 428. Thus | | (j-141909)/428 should be a standard normal variate (z score)| |that leads to a uniform [0,1) p value. The test is repeated | |twenty times. | |-------------------------------------------------------------| THE OVERLAPPING 20-TUPLES BITSTREAM TEST for ./rand.data (20 bits/word, 2097152 words 20 bitstreams. No. missing words should average 141909.33 with sigma=428.00.) ---------------------------------------------------------------- BITSTREAM test results for ./rand.data. Bitstream No. missing words z-score p-value 1 142778 2.03 0.021198 2 142204 0.69 0.245575 3 141611 -0.70 0.757109 4 141918 0.02 0.491919 5 141598 -0.73 0.766511 6 141912 0.01 0.497511 7 141806 -0.24 0.595387 8 141824 -0.20 0.579013 9 141291 -1.44 0.925728 10 141752 -0.37 0.643412 11 142316 0.95 0.171015 12 142738 1.94 0.026425 13 142832 2.16 0.015551 14 141164 -1.74 0.959195 15 141668 -0.56 0.713574 16 141299 -1.43 0.923066 17 142177 0.63 0.265855 18 142212 0.71 0.239729 19 141341 -1.33 0.907890 20 142960 2.45 0.007047 ---------------------------------------------------------------- |-------------------------------------------------------------| | OPSO means Overlapping-Pairs-Sparse-Occupancy | |The OPSO test considers 2-letter words from an alphabet of | |1024 letters. Each letter is determined by a specified ten | |bits from a 32-bit integer in the sequence to be tested. OPSO| |generates 2^21 (overlapping) 2-letter words (from 2^21+1 | |"keystrokes") and counts the number of missing words---that | |is 2-letter words which do not appear in the entire sequence.| |That count should be very close to normally distributed with | |mean 141,909, sigma 290. Thus (missingwrds-141909)/290 should| |be a standard normal variable. The OPSO test takes 32 bits at| |a time from the test file and uses a designated set of ten | |consecutive bits. It then restarts the file for the next de- | |signated 10 bits, and so on. | |------------------------------------------------------------ | OPSO test for file ./rand.data Bits used No. missing words z-score p-value 23 to 32 141676 -0.8046 0.789471 22 to 31 142253 1.1851 0.117995 21 to 30 141936 0.0920 0.463363 20 to 29 141676 -0.8046 0.789471 19 to 28 141877 -0.1115 0.544383 18 to 27 142283 1.2885 0.098783 17 to 26 142332 1.4575 0.072492 16 to 25 141994 0.2920 0.385156 15 to 24 141476 -1.4942 0.932444 14 to 23 141705 -0.7046 0.759466 13 to 22 142569 2.2747 0.011461 12 to 21 141666 -0.8391 0.799285 11 to 20 141672 -0.8184 0.793430 10 to 19 141973 0.2196 0.413110 9 to 18 141835 -0.2563 0.601144 8 to 17 141752 -0.5425 0.706269 7 to 16 141836 -0.2529 0.599813 6 to 15 141555 -1.2218 0.889114 5 to 14 141569 -1.1736 0.879713 4 to 13 142097 0.6471 0.258771 3 to 12 141875 -0.1184 0.547116 2 to 11 141311 -2.0632 0.980454 1 to 10 141440 -1.6184 0.947210 ----------------------------------------------------------------- |------------------------------------------------------------ | | OQSO means Overlapping-Quadruples-Sparse-Occupancy | | The test OQSO is similar, except that it considers 4-letter| |words from an alphabet of 32 letters, each letter determined | |by a designated string of 5 consecutive bits from the test | |file, elements of which are assumed 32-bit random integers. | |The mean number of missing words in a sequence of 2^21 four- | |letter words, (2^21+3 "keystrokes"), is again 141909, with | |sigma = 295. The mean is based on theory; sigma comes from | |extensive simulation. | |------------------------------------------------------------ | OQSO test for file ./rand.data Bits used No. missing words z-score p-value 28 to 32 142058 0.5040 0.307143 27 to 31 141735 -0.5909 0.722723 26 to 30 141650 -0.8791 0.810322 25 to 29 142143 0.7921 0.214151 24 to 28 142197 0.9752 0.164742 23 to 27 141987 0.2633 0.396164 22 to 26 141260 -2.2011 0.986136 21 to 25 142192 0.9582 0.168980 20 to 24 141527 -1.2960 0.902518 19 to 23 141875 -0.1164 0.546321 18 to 22 141727 -0.6181 0.731735 17 to 21 142261 1.1921 0.116611 16 to 20 141614 -1.0011 0.841615 15 to 19 142050 0.4768 0.316735 14 to 18 142124 0.7277 0.233400 13 to 17 141925 0.0531 0.478819 12 to 16 141977 0.2294 0.409283 11 to 15 141811 -0.3333 0.630554 10 to 14 142335 1.4429 0.074517 9 to 13 142229 1.0836 0.139265 8 to 12 142199 0.9819 0.163067 7 to 11 142321 1.3955 0.081434 6 to 10 141483 -1.4452 0.925797 5 to 9 141727 -0.6181 0.731735 4 to 8 141610 -1.0147 0.844870 3 to 7 141586 -1.0960 0.863468 2 to 6 141734 -0.5943 0.723857 1 to 5 141597 -1.0587 0.855142 ----------------------------------------------------------------- |------------------------------------------------------------ | | The DNA test considers an alphabet of 4 letters: C,G,A,T,| |determined by two designated bits in the sequence of random | |integers being tested. It considers 10-letter words, so that| |as in OPSO and OQSO, there are 2^20 possible words, and the | |mean number of missing words from a string of 2^21 (over- | |lapping) 10-letter words (2^21+9 "keystrokes") is 141909. | |The standard deviation sigma=339 was determined as for OQSO | |by simulation. (Sigma for OPSO, 290, is the true value (to | |three places), not determined by simulation. | |------------------------------------------------------------ | DNA test for file ./rand.data Bits used No. missing words z-score p-value 31 to 32 141704 -0.6057 0.727641 30 to 31 142195 0.8427 0.199702 29 to 30 142360 1.3294 0.091856 28 to 29 141913 0.0108 0.495681 27 to 28 141432 -1.4081 0.920442 26 to 27 142374 1.3707 0.085233 25 to 26 142275 1.0787 0.140367 24 to 25 142440 1.5654 0.058745 23 to 24 142034 0.3678 0.356527 22 to 23 142849 2.7719 0.002787 21 to 22 141850 -0.1750 0.569466 20 to 21 141953 0.1288 0.448750 19 to 20 142208 0.8810 0.189150 18 to 19 142042 0.3914 0.347767 17 to 18 141491 -1.2340 0.891401 16 to 17 142085 0.5182 0.302159 15 to 16 142712 2.3678 0.008948 14 to 15 141747 -0.4788 0.683977 13 to 14 141941 0.0934 0.462784 12 to 13 141772 -0.4051 0.657299 11 to 12 141874 -0.1042 0.541502 10 to 11 141813 -0.2842 0.611856 9 to 10 141987 0.2291 0.409390 8 to 9 142153 0.7188 0.236135 7 to 8 141645 -0.7797 0.782226 6 to 7 141947 0.1111 0.455760 5 to 6 141878 -0.0924 0.536817 4 to 5 141668 -0.7119 0.761733 3 to 4 142053 0.4238 0.335854 2 to 3 142184 0.8102 0.208902 1 to 2 141457 -1.3343 0.908948 ----------------------------------------------------------------- |-------------------------------------------------------------| | This is the COUNT-THE-1''s TEST on a stream of bytes. | |Consider the file under test as a stream of bytes (four per | |32 bit integer). Each byte can contain from 0 to 8 1''s, | |with probabilities 1,8,28,56,70,56,28,8,1 over 256. Now let | |the stream of bytes provide a string of overlapping 5-letter| |words, each "letter" taking values A,B,C,D,E. The letters are| |determined by the number of 1''s in a byte: 0,1,or 2 yield A,| |3 yields B, 4 yields C, 5 yields D and 6,7 or 8 yield E. Thus| |we have a monkey at a typewriter hitting five keys with vari-| |ous probabilities (37,56,70,56,37 over 256). There are 5^5 | |possible 5-letter words, and from a string of 256,000 (over- | |lapping) 5-letter words, counts are made on the frequencies | |for each word. The quadratic form in the weak inverse of | |the covariance matrix of the cell counts provides a chisquare| |test: Q5-Q4, the difference of the naive Pearson sums of | |(OBS-EXP)^2/EXP on counts for 5- and 4-letter cell counts. | |-------------------------------------------------------------| Test result for the byte stream from ./rand.data (Degrees of freedom: 5^4-5^3=2500; sample size: 2560000) chisquare z-score p-value 2587.23 1.234 0.108669 |-------------------------------------------------------------| | This is the COUNT-THE-1''s TEST for specific bytes. | |Consider the file under test as a stream of 32-bit integers. | |From each integer, a specific byte is chosen , say the left- | |most: bits 1 to 8. Each byte can contain from 0 to 8 1''s, | |with probabilitie 1,8,28,56,70,56,28,8,1 over 256. Now let | |the specified bytes from successive integers provide a string| |of (overlapping) 5-letter words, each "letter" taking values | |A,B,C,D,E. The letters are determined by the number of 1''s,| |in that byte: 0,1,or 2 ---> A, 3 ---> B, 4 ---> C, 5 ---> D, | |and 6,7 or 8 ---> E. Thus we have a monkey at a typewriter | |hitting five keys with with various probabilities: 37,56,70, | |56,37 over 256. There are 5^5 possible 5-letter words, and | |from a string of 256,000 (overlapping) 5-letter words, counts| |are made on the frequencies for each word. The quadratic form| |in the weak inverse of the covariance matrix of the cell | |counts provides a chisquare test: Q5-Q4, the difference of | |the naive Pearson sums of (OBS-EXP)^2/EXP on counts for 5- | |and 4-letter cell counts. | |-------------------------------------------------------------| Test results for specific bytes from ./rand.data (Degrees of freedom: 5^4-5^3=2500; sample size: 256000) bits used chisquare z-score p-value 1 to 8 2526.10 0.369 0.356032 2 to 9 2440.65 -0.839 0.799360 3 to 10 2566.91 0.946 0.172026 4 to 11 2322.74 -2.507 0.993909 5 to 12 2465.71 -0.485 0.686150 6 to 13 2487.88 -0.171 0.568033 7 to 14 2588.80 1.256 0.104599 8 to 15 2604.46 1.477 0.069796 9 to 16 2550.58 0.715 0.237205 10 to 17 2482.12 -0.253 0.599834 11 to 18 2381.13 -1.681 0.953624 12 to 19 2472.81 -0.385 0.649704 13 to 20 2519.89 0.281 0.389223 14 to 21 2472.09 -0.395 0.653462 15 to 22 2512.22 0.173 0.431416 16 to 23 2510.57 0.149 0.440583 17 to 24 2555.79 0.789 0.215069 18 to 25 2459.37 -0.575 0.717198 19 to 26 2527.69 0.392 0.347674 20 to 27 2649.11 2.109 0.017485 21 to 28 2406.89 -1.317 0.906040 22 to 29 2771.29 3.837 0.000062 23 to 30 2412.49 -1.238 0.892076 24 to 31 2449.72 -0.711 0.761463 25 to 32 2500.76 0.011 0.495733 |-------------------------------------------------------------| | THIS IS A PARKING LOT TEST | |In a square of side 100, randomly "park" a car---a circle of | |radius 1. Then try to park a 2nd, a 3rd, and so on, each | |time parking "by ear". That is, if an attempt to park a car | |causes a crash with one already parked, try again at a new | |random location. (To avoid path problems, consider parking | |helicopters rather than cars.) Each attempt leads to either| |a crash or a success, the latter followed by an increment to | |the list of cars already parked. If we plot n: the number of | |attempts, versus k: the number successfully parked, we get a | |curve that should be similar to those provided by a perfect | |random number generator. Theory for the behavior of such a | |random curve seems beyond reach, and as graphics displays are| |not available for this battery of tests, a simple characteriz| |ation of the random experiment is used: k, the number of cars| |successfully parked after n=12,000 attempts. Simulation shows| |that k should average 3523 with sigma 21.9 and is very close | |to normally distributed. Thus (k-3523)/21.9 should be a st- | |andard normal variable, which, converted to a uniform varia- | |ble, provides input to a KSTEST based on a sample of 10. | |-------------------------------------------------------------| CDPARK: result of 10 tests on file ./rand.data (Of 12000 tries, the average no. of successes should be 3523.0 with sigma=21.9) No. succeses z-score p-value 3523 0.0000 0.500000 3519 -0.1826 0.572463 3517 -0.2740 0.607947 3532 0.4110 0.340551 3530 0.3196 0.374623 3517 -0.2740 0.607947 3501 -1.0046 0.842447 3514 -0.4110 0.659449 3528 0.2283 0.409702 3516 -0.3196 0.625377 Square side=100, avg. no. parked=3519.70 sample std.=8.65 p-value of the KSTEST for those 10 p-values: 0.181146 |-------------------------------------------------------------| | THE MINIMUM DISTANCE TEST | |It does this 100 times: choose n=8000 random points in a | |square of side 10000. Find d, the minimum distance between | |the (n^2-n)/2 pairs of points. If the points are truly inde-| |pendent uniform, then d^2, the square of the minimum distance| |should be (very close to) exponentially distributed with mean| |.995 . Thus 1-exp(-d^2/.995) should be uniform on [0,1) and | |a KSTEST on the resulting 100 values serves as a test of uni-| |formity for random points in the square. Test numbers=0 mod 5| |are printed but the KSTEST is based on the full set of 100 | |random choices of 8000 points in the 10000x10000 square. | |-------------------------------------------------------------| This is the MINIMUM DISTANCE test for file ./rand.data Sample no. d^2 mean equiv uni 5 0.2126 0.8322 0.192400 10 0.5124 1.1998 0.402464 15 2.1015 1.3764 0.879006 20 0.4745 1.4543 0.379317 25 1.8478 1.4276 0.843867 30 1.3684 1.3057 0.747222 35 0.7487 1.1959 0.528813 40 0.5955 1.1290 0.450361 45 1.0423 1.1412 0.649203 50 5.0267 1.2392 0.993603 55 0.7735 1.2576 0.540387 60 0.8330 1.1965 0.567070 65 0.2339 1.1440 0.209525 70 0.5272 1.0935 0.411293 75 0.3519 1.1152 0.297864 80 0.7128 1.0777 0.511503 85 0.1116 1.0789 0.106111 90 0.3544 1.0650 0.299680 95 0.0440 1.0689 0.043273 100 1.3961 1.0842 0.754176 -------------------------------------------------------------- Result of KS test on 100 transformed mindist^2's: p-value=0.683156 |-------------------------------------------------------------| | THE 3DSPHERES TEST | |Choose 4000 random points in a cube of edge 1000. At each | |point, center a sphere large enough to reach the next closest| |point. Then the volume of the smallest such sphere is (very | |close to) exponentially distributed with mean 120pi/3. Thus | |the radius cubed is exponential with mean 30. (The mean is | |obtained by extensive simulation). The 3DSPHERES test gener-| |ates 4000 such spheres 20 times. Each min radius cubed leads| |to a uniform variable by means of 1-exp(-r^3/30.), then a | | KSTEST is done on the 20 p-values. | |-------------------------------------------------------------| The 3DSPHERES test for file ./rand.data sample no r^3 equiv. uni. 1 63.824 0.880861 2 1.497 0.048682 3 33.490 0.672519 4 16.928 0.431214 5 30.495 0.638137 6 49.325 0.806823 7 19.096 0.470877 8 7.406 0.218748 9 26.382 0.584970 10 17.329 0.438767 11 25.113 0.567033 12 19.479 0.477589 13 53.015 0.829183 14 27.940 0.605971 15 7.108 0.210952 16 15.597 0.405412 17 27.391 0.598700 18 24.051 0.551434 19 60.719 0.867872 20 17.062 0.433760 -------------------------------------------------------------- p-value for KS test on those 20 p-values: 0.263638 |-------------------------------------------------------------| | This is the SQUEEZE test | | Random integers are floated to get uniforms on [0,1). Start-| | ing with k=2^31=2147483647, the test finds j, the number of | | iterations necessary to reduce k to 1, using the reduction | | k=ceiling(k*U), with U provided by floating integers from | | the file being tested. Such j''s are found 100,000 times, | | then counts for the number of times j was <=6,7,...,47,>=48 | | are used to provide a chi-square test for cell frequencies. | |-------------------------------------------------------------| RESULTS OF SQUEEZE TEST FOR ./rand.data Table of standardized frequency counts (obs-exp)^2/exp for j=(1,..,6), 7,...,47,(48,...) -0.1 0.5 1.3 -1.0 -0.4 -0.7 -0.2 0.3 0.3 0.8 1.3 -0.4 0.8 -0.8 -1.2 0.4 1.3 1.0 -1.0 0.7 -0.2 -1.1 0.6 -1.2 -1.7 0.3 0.6 0.3 0.5 -0.0 -1.5 1.4 -0.4 -0.6 -0.8 -0.5 -1.2 -0.7 -0.8 4.3 -0.6 -1.0 -1.1 Chi-square with 42 degrees of freedom:49.169081 z-score=0.782211, p-value=0.207962 _____________________________________________________________ |-------------------------------------------------------------| | The OVERLAPPING SUMS test | |Integers are floated to get a sequence U(1),U(2),... of uni- | |form [0,1) variables. Then overlapping sums, | | S(1)=U(1)+...+U(100), S2=U(2)+...+U(101),... are formed. | |The S''s are virtually normal with a certain covariance mat- | |rix. A linear transformation of the S''s converts them to a | |sequence of independent standard normals, which are converted| |to uniform variables for a KSTEST. | |-------------------------------------------------------------| Results of the OSUM test for ./rand.data Test no p-value 1 0.658759 2 0.168429 3 0.148721 4 0.010344 5 0.198190 6 0.538346 7 0.635193 8 0.687959 9 0.000132 10 0.036327 _____________________________________________________________ p-value for 10 kstests on 100 kstests:0.012032 |-------------------------------------------------------------| | This is the RUNS test. It counts runs up, and runs down,| |in a sequence of uniform [0,1) variables, obtained by float- | |ing the 32-bit integers in the specified file. This example | |shows how runs are counted: .123,.357,.789,.425,.224,.416,.95| |contains an up-run of length 3, a down-run of length 2 and an| |up-run of (at least) 2, depending on the next values. The | |covariance matrices for the runs-up and runs-down are well | |known, leading to chisquare tests for quadratic forms in the | |weak inverses of the covariance matrices. Runs are counted | |for sequences of length 10,000. This is done ten times. Then| |another three sets of ten. | |-------------------------------------------------------------| The RUNS test for file ./rand.data (Up and down runs in a sequence of 10000 numbers) Set 1 runs up; ks test for 10 p's: 0.486019 runs down; ks test for 10 p's: 0.031314 Set 2 runs up; ks test for 10 p's: 0.751930 runs down; ks test for 10 p's: 0.610006 |-------------------------------------------------------------| |This the CRAPS TEST. It plays 200,000 games of craps, counts| |the number of wins and the number of throws necessary to end | |each game. The number of wins should be (very close to) a | |normal with mean 200000p and variance 200000p(1-p), and | |p=244/495. Throws necessary to complete the game can vary | |from 1 to infinity, but counts for all>21 are lumped with 21.| |A chi-square test is made on the no.-of-throws cell counts. | |Each 32-bit integer from the test file provides the value for| |the throw of a die, by floating to [0,1), multiplying by 6 | |and taking 1 plus the integer part of the result. | |-------------------------------------------------------------| RESULTS OF CRAPS TEST FOR ./rand.data No. of wins: Observed Expected 98208 98585.858586 z-score=-1.690, pvalue=0.95449 Analysis of Throws-per-Game: Throws Observed Expected Chisq Sum of (O-E)^2/E 1 66440 66666.7 0.771 0.771 2 37710 37654.3 0.082 0.853 3 27039 26954.7 0.263 1.116 4 19373 19313.5 0.184 1.300 5 13848 13851.4 0.001 1.301 6 9947 9943.5 0.001 1.302 7 7196 7145.0 0.364 1.666 8 5127 5139.1 0.028 1.694 9 3716 3699.9 0.070 1.764 10 2587 2666.3 2.358 4.123 11 1921 1923.3 0.003 4.126 12 1377 1388.7 0.099 4.225 13 1046 1003.7 1.781 6.006 14 746 726.1 0.543 6.549 15 487 525.8 2.868 9.418 16 415 381.2 3.006 12.424 17 263 276.5 0.663 13.087 18 220 200.8 1.830 14.916 19 130 146.0 1.750 16.667 20 108 106.2 0.030 16.697 21 304 287.1 0.993 17.690 Chisq= 17.69 for 20 degrees of freedom, p= 0.60784 SUMMARY of craptest on ./rand.data p-value for no. of wins: 0.954486 p-value for throws/game: 0.607835 _____________________________________________________________