Script started on Wed Nov 22 10:53:31 2006 bash2-2.05b$ ./diehard 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: out warning: this program uses gets(), which is unsafe. 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. 16 |-------------------------------------------------------------| | 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 out (no_bdays=1024, no_days/yr=2^24, lambda=16.00, sample size=500) Bits used mean chisqr p-value 1 to 24 15.79 15.0259 0.593617 2 to 25 15.97 22.7500 0.157567 3 to 26 15.60 13.6301 0.693094 4 to 27 15.75 10.1279 0.898160 5 to 28 15.77 9.1666 0.934891 6 to 29 15.78 13.3362 0.713408 7 to 30 15.67 16.2426 0.506705 8 to 31 15.63 25.5946 0.082169 9 to 32 15.77 11.9550 0.802854 degree of freedoms is: 17 --------------------------------------------------------------- p-value for KStest on those 9 p-values: 0.503913 |-------------------------------------------------------------| | 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=76.505036 with df=99; p-value= 0.954532 _______________________________________________________________ sample 2 chisquare=94.941811 with df=99; p-value= 0.596724 _______________________________________________________________ |-------------------------------------------------------------| |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 out RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=28 196 211.4 1.124 1.124 r=29 5154 5134.0 0.078 1.202 r=30 23163 23103.0 0.156 1.358 r=31 11487 11551.5 0.360 1.718 chi-square = 1.718 with df = 3; p-value = 0.633 -------------------------------------------------------------- |-------------------------------------------------------------| |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 out RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=29 218 211.4 0.205 0.205 r=30 5183 5134.0 0.467 0.672 r=31 23150 23103.0 0.095 0.768 r=32 11449 11551.5 0.910 1.678 chi-square = 1.678 with df = 3; p-value = 0.642 -------------------------------------------------------------- |-------------------------------------------------------------| |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 out bits 1 to 8 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 1008 944.3 4.297 4.297 r=5 21676 21743.9 0.212 4.509 r=6 77316 77311.8 0.000 4.509 chi-square = 4.509 with df = 2; p-value = 0.105 -------------------------------------------------------------- bits 2 to 9 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 1015 944.3 5.293 5.293 r=5 21576 21743.9 1.296 6.590 r=6 77409 77311.8 0.122 6.712 chi-square = 6.712 with df = 2; p-value = 0.035 -------------------------------------------------------------- bits 3 to 10 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 955 944.3 0.121 0.121 r=5 21782 21743.9 0.067 0.188 r=6 77263 77311.8 0.031 0.219 chi-square = 0.219 with df = 2; p-value = 0.896 -------------------------------------------------------------- bits 4 to 11 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 946 944.3 0.003 0.003 r=5 21604 21743.9 0.900 0.903 r=6 77450 77311.8 0.247 1.150 chi-square = 1.150 with df = 2; p-value = 0.563 -------------------------------------------------------------- bits 5 to 12 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 1023 944.3 6.559 6.559 r=5 21541 21743.9 1.893 8.452 r=6 77436 77311.8 0.200 8.652 chi-square = 8.652 with df = 2; p-value = 0.013 -------------------------------------------------------------- bits 6 to 13 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 943 944.3 0.002 0.002 r=5 21521 21743.9 2.285 2.287 r=6 77536 77311.8 0.650 2.937 chi-square = 2.937 with df = 2; p-value = 0.230 -------------------------------------------------------------- bits 7 to 14 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 937 944.3 0.056 0.056 r=5 21736 21743.9 0.003 0.059 r=6 77327 77311.8 0.003 0.062 chi-square = 0.062 with df = 2; p-value = 0.969 -------------------------------------------------------------- bits 8 to 15 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 947 944.3 0.008 0.008 r=5 21874 21743.9 0.778 0.786 r=6 77179 77311.8 0.228 1.014 chi-square = 1.014 with df = 2; p-value = 0.602 -------------------------------------------------------------- bits 9 to 16 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 936 944.3 0.073 0.073 r=5 21785 21743.9 0.078 0.151 r=6 77279 77311.8 0.014 0.165 chi-square = 0.165 with df = 2; p-value = 0.921 -------------------------------------------------------------- bits 10 to 17 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 966 944.3 0.499 0.499 r=5 21647 21743.9 0.432 0.930 r=6 77387 77311.8 0.073 1.004 chi-square = 1.004 with df = 2; p-value = 0.605 -------------------------------------------------------------- bits 11 to 18 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 927 944.3 0.317 0.317 r=5 21872 21743.9 0.755 1.072 r=6 77201 77311.8 0.159 1.230 chi-square = 1.230 with df = 2; p-value = 0.541 -------------------------------------------------------------- bits 12 to 19 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 974 944.3 0.934 0.934 r=5 21906 21743.9 1.208 2.143 r=6 77120 77311.8 0.476 2.618 chi-square = 2.618 with df = 2; p-value = 0.270 -------------------------------------------------------------- bits 13 to 20 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 935 944.3 0.092 0.092 r=5 21979 21743.9 2.542 2.634 r=6 77086 77311.8 0.659 3.293 chi-square = 3.293 with df = 2; p-value = 0.193 -------------------------------------------------------------- bits 14 to 21 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 927 944.3 0.317 0.317 r=5 21996 21743.9 2.923 3.240 r=6 77077 77311.8 0.713 3.953 chi-square = 3.953 with df = 2; p-value = 0.139 -------------------------------------------------------------- bits 15 to 22 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 926 944.3 0.355 0.355 r=5 21879 21743.9 0.839 1.194 r=6 77195 77311.8 0.176 1.371 chi-square = 1.371 with df = 2; p-value = 0.504 -------------------------------------------------------------- bits 16 to 23 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 942 944.3 0.006 0.006 r=5 21936 21743.9 1.697 1.703 r=6 77122 77311.8 0.466 2.169 chi-square = 2.169 with df = 2; p-value = 0.338 -------------------------------------------------------------- bits 17 to 24 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 960 944.3 0.261 0.261 r=5 21915 21743.9 1.346 1.607 r=6 77125 77311.8 0.451 2.059 chi-square = 2.059 with df = 2; p-value = 0.357 -------------------------------------------------------------- bits 18 to 25 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 911 944.3 1.174 1.174 r=5 21872 21743.9 0.755 1.929 r=6 77217 77311.8 0.116 2.045 chi-square = 2.045 with df = 2; p-value = 0.360 -------------------------------------------------------------- bits 19 to 26 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 966 944.3 0.499 0.499 r=5 21744 21743.9 0.000 0.499 r=6 77290 77311.8 0.006 0.505 chi-square = 0.505 with df = 2; p-value = 0.777 -------------------------------------------------------------- bits 20 to 27 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 1003 944.3 3.649 3.649 r=5 21603 21743.9 0.913 4.562 r=6 77394 77311.8 0.087 4.649 chi-square = 4.649 with df = 2; p-value = 0.098 -------------------------------------------------------------- bits 21 to 28 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 1026 944.3 7.069 7.069 r=5 21665 21743.9 0.286 7.355 r=6 77309 77311.8 0.000 7.355 chi-square = 7.355 with df = 2; p-value = 0.025 -------------------------------------------------------------- bits 22 to 29 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 1011 944.3 4.711 4.711 r=5 21784 21743.9 0.074 4.785 r=6 77205 77311.8 0.148 4.933 chi-square = 4.933 with df = 2; p-value = 0.085 -------------------------------------------------------------- bits 23 to 30 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 940 944.3 0.020 0.020 r=5 21795 21743.9 0.120 0.140 r=6 77265 77311.8 0.028 0.168 chi-square = 0.168 with df = 2; p-value = 0.919 -------------------------------------------------------------- bits 24 to 31 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 941 944.3 0.012 0.012 r=5 21768 21743.9 0.027 0.038 r=6 77291 77311.8 0.006 0.044 chi-square = 0.044 with df = 2; p-value = 0.978 -------------------------------------------------------------- bits 25 to 32 RANK OBSERVED EXPECTED (O-E)^2/E SUM r<=4 945 944.3 0.001 0.001 r=5 21732 21743.9 0.007 0.007 r=6 77323 77311.8 0.002 0.009 chi-square = 0.009 with df = 2; p-value = 0.996 -------------------------------------------------------------- TEST SUMMARY, 25 tests on 100,000 random 6x8 matrices These should be 25 uniform [0,1] random variates: 0.104910 0.034874 0.896369 0.562644 0.013221 0.230278 0.969334 0.602222 0.921016 0.605428 0.540529 0.270036 0.192721 0.138560 0.503962 0.338122 0.357232 0.359655 0.776929 0.097815 0.025286 0.084890 0.919431 0.978319 0.995682 The KS test for those 25 supposed UNI's yields KS p-value = 0.221359 |-------------------------------------------------------------| | 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 out (20 bits/word, 2097152 words 20 bitstreams. No. missing words should average 141909.33 with sigma=428.00.) ---------------------------------------------------------------- BITSTREAM test results for out. Bitstream No. missing words z-score p-value 1 141969 0.14 0.444561 2 141968 0.14 0.445484 3 141854 -0.13 0.551430 4 141739 -0.40 0.654673 5 141297 -1.43 0.923739 6 142221 0.73 0.233245 7 141339 -1.33 0.908660 8 141897 -0.03 0.511491 9 141710 -0.47 0.679294 10 141575 -0.78 0.782641 11 141421 -1.14 0.873056 12 142044 0.31 0.376514 13 141530 -0.89 0.812268 14 141855 -0.13 0.550506 15 142446 1.25 0.104939 16 141369 -1.26 0.896607 17 142172 0.61 0.269702 18 141529 -0.89 0.812897 19 142566 1.53 0.062481 20 141996 0.20 0.419763 ---------------------------------------------------------------- |-------------------------------------------------------------| | 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 out Bits used No. missing words z-score p-value 23 to 32 141878 -0.1080 0.543016 22 to 31 141884 -0.0873 0.534801 21 to 30 141615 -1.0149 0.844931 20 to 29 141910 0.0023 0.499078 19 to 28 141538 -1.2804 0.899806 18 to 27 142143 0.8058 0.210191 17 to 26 142096 0.6437 0.259888 16 to 25 142049 0.4816 0.315038 15 to 24 141435 -1.6356 0.949040 14 to 23 141569 -1.1736 0.879713 13 to 22 141760 -0.5149 0.696699 12 to 21 141953 0.1506 0.440151 11 to 20 141908 -0.0046 0.501830 10 to 19 142146 0.8161 0.207220 9 to 18 142033 0.4264 0.334891 8 to 17 142014 0.3609 0.359075 7 to 16 142593 2.3575 0.009200 6 to 15 142233 1.1161 0.132189 5 to 14 142100 0.6575 0.255435 4 to 13 142001 0.3161 0.375962 3 to 12 141749 -0.5529 0.709821 2 to 11 142034 0.4299 0.333635 1 to 10 141446 -1.5977 0.944944 ----------------------------------------------------------------- |------------------------------------------------------------ | | 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 out Bits used No. missing words z-score p-value 28 to 32 141491 -1.4181 0.921914 27 to 31 142058 0.5040 0.307143 26 to 30 142495 1.9853 0.023554 25 to 29 141967 0.1955 0.422504 24 to 28 142374 1.5752 0.057611 23 to 27 142159 0.8463 0.198682 22 to 26 141833 -0.2587 0.602084 21 to 25 141733 -0.5977 0.724990 20 to 24 141911 0.0057 0.497742 19 to 23 142030 0.4091 0.341251 18 to 22 142042 0.4497 0.326453 17 to 21 142304 1.3379 0.090470 16 to 20 142160 0.8497 0.197738 15 to 19 142009 0.3379 0.367733 14 to 18 141616 -0.9943 0.839971 13 to 17 142093 0.6226 0.266770 12 to 16 141575 -1.1333 0.871460 11 to 15 141531 -1.2825 0.900162 10 to 14 141954 0.1514 0.439821 9 to 13 142231 1.0904 0.137767 8 to 12 142384 1.6091 0.053803 7 to 11 142232 1.0938 0.137022 6 to 10 141868 -0.1401 0.555710 5 to 9 141616 -0.9943 0.839971 4 to 8 142250 1.1548 0.124083 3 to 7 141446 -1.5706 0.941863 2 to 6 142530 2.1040 0.017691 1 to 5 142251 1.1582 0.123390 ----------------------------------------------------------------- |------------------------------------------------------------ | | 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 out Bits used No. missing words z-score p-value 31 to 32 142042 0.3914 0.347767 30 to 31 141423 -1.4346 0.924300 29 to 30 142591 2.0108 0.022172 28 to 29 142187 0.8191 0.206369 27 to 28 142003 0.2763 0.391154 26 to 27 141574 -0.9892 0.838711 25 to 26 141120 -2.3284 0.990055 24 to 25 141977 0.1996 0.420890 23 to 24 141928 0.0551 0.478040 22 to 23 141169 -2.1839 0.985514 21 to 22 141687 -0.6558 0.744037 20 to 21 142035 0.3707 0.355427 19 to 20 141679 -0.6794 0.751570 18 to 19 142548 1.8840 0.029784 17 to 18 141777 -0.3904 0.651863 16 to 17 142122 0.6273 0.265216 15 to 16 141149 -2.2429 0.987547 14 to 15 141841 -0.2016 0.579871 13 to 14 141519 -1.1514 0.875219 12 to 13 141865 -0.1308 0.552020 11 to 12 141328 -1.7148 0.956812 10 to 11 141823 -0.2547 0.600507 9 to 10 141668 -0.7119 0.761733 8 to 9 141296 -1.8092 0.964793 7 to 8 141819 -0.2665 0.605058 6 to 7 142113 0.6008 0.273988 5 to 6 141841 -0.2016 0.579871 4 to 5 141889 -0.0600 0.523910 3 to 4 142577 1.9695 0.024446 2 to 3 141160 -2.2104 0.986462 1 to 2 142013 0.3058 0.379874 ----------------------------------------------------------------- |-------------------------------------------------------------| | 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 out (Degrees of freedom: 5^4-5^3=2500; sample size: 2560000) chisquare z-score p-value 2417.61 -1.165 0.878018 |-------------------------------------------------------------| | 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 out (Degrees of freedom: 5^4-5^3=2500; sample size: 256000) bits used chisquare z-score p-value 1 to 8 2380.61 -1.688 0.954341 2 to 9 2557.19 0.809 0.209311 3 to 10 2424.11 -1.073 0.858429 4 to 11 2526.48 0.374 0.354023 5 to 12 2594.56 1.337 0.090569 6 to 13 2431.59 -0.967 0.833327 7 to 14 2585.30 1.206 0.113835 8 to 15 2589.45 1.265 0.102938 9 to 16 2635.85 1.921 0.027355 10 to 17 2598.49 1.393 0.081826 11 to 18 2460.38 -0.560 0.712381 12 to 19 2512.48 0.177 0.429937 13 to 20 2524.53 0.347 0.364305 14 to 21 2507.88 0.111 0.455655 15 to 22 2447.48 -0.743 0.771187 16 to 23 2411.81 -1.247 0.893843 17 to 24 2463.23 -0.520 0.698471 18 to 25 2516.17 0.229 0.409554 19 to 26 2368.95 -1.853 0.968078 20 to 27 2588.41 1.250 0.105597 21 to 28 2411.91 -1.246 0.893580 22 to 29 2452.64 -0.670 0.748496 23 to 30 2510.43 0.148 0.441360 24 to 31 2528.67 0.405 0.342593 25 to 32 2536.87 0.521 0.301019 |-------------------------------------------------------------| | 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 out (Of 12000 tries, the average no. of successes should be 3523.0 with sigma=21.9) No. succeses z-score p-value 3561 1.7352 0.041356 3502 -0.9589 0.831196 3519 -0.1826 0.572463 3504 -0.8676 0.807188 3514 -0.4110 0.659449 3534 0.5023 0.307734 3563 1.8265 0.033889 3552 1.3242 0.092718 3540 0.7763 0.218799 3559 1.6438 0.050105 Square side=100, avg. no. parked=3534.80 sample std.=22.58 p-value of the KSTEST for those 10 p-values: 0.099690 |-------------------------------------------------------------| | 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 out Sample no. d^2 mean equiv uni 5 0.3583 1.0240 0.302424 10 0.4995 0.8930 0.394703 15 3.1347 1.0448 0.957168 20 0.7916 1.1965 0.548680 25 0.0845 1.0004 0.081411 30 2.3320 0.9518 0.904031 35 2.8494 1.0792 0.942944 40 0.7958 1.0855 0.550575 45 0.4682 1.0902 0.375352 50 1.6092 1.2010 0.801565 55 0.3796 1.1403 0.317150 60 1.1361 1.1573 0.680758 65 1.7955 1.2022 0.835453 70 1.1236 1.1917 0.676715 75 0.7428 1.1342 0.525988 80 4.2128 1.1695 0.985506 85 0.0320 1.1803 0.031639 90 0.1784 1.1602 0.164137 95 0.5726 1.1310 0.437554 100 0.0058 1.1055 0.005857 -------------------------------------------------------------- Result of KS test on 100 transformed mindist^2's: p-value=0.454463 |-------------------------------------------------------------| | 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 out sample no r^3 equiv. uni. 1 36.884 0.707556 2 22.173 0.522454 3 33.133 0.668599 4 0.138 0.004596 5 6.924 0.206097 6 4.134 0.128723 7 84.130 0.939453 8 57.072 0.850788 9 41.852 0.752187 10 18.850 0.466514 11 12.367 0.337820 12 40.421 0.740075 13 25.918 0.578494 14 43.117 0.762412 15 2.587 0.082609 16 0.026 0.000872 17 13.915 0.371128 18 20.473 0.494607 19 2.279 0.073157 20 45.897 0.783440 -------------------------------------------------------------- p-value for KS test on those 20 p-values: 0.445832 |-------------------------------------------------------------| | 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 out Table of standardized frequency counts (obs-exp)^2/exp for j=(1,..,6), 7,...,47,(48,...) 0.6 0.1 0.8 0.6 1.9 -0.3 0.7 0.7 -0.1 -0.1 -1.3 -1.3 0.5 -1.5 0.4 -0.3 0.1 0.5 1.1 1.3 -0.7 -1.1 2.4 0.0 -1.0 0.2 -0.3 -0.2 -0.8 -0.7 0.1 -0.8 -0.5 -0.8 1.5 -0.8 0.7 0.8 -0.4 -0.1 0.1 0.0 1.8 Chi-square with 42 degrees of freedom:34.334053 z-score=-0.836423, p-value=0.793761 _____________________________________________________________ |-------------------------------------------------------------| | 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 out Test no p-value 1 0.005127 2 0.374750 3 0.132884 4 0.012645 5 0.019421 6 0.376090 7 0.048664 8 0.846210 9 0.055690 10 0.408177 _____________________________________________________________ p-value for 10 kstests on 100 kstests:0.000533 |-------------------------------------------------------------| | 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 out (Up and down runs in a sequence of 10000 numbers) Set 1 runs up; ks test for 10 p's: 0.293182 runs down; ks test for 10 p's: 0.020964 Set 2 runs up; ks test for 10 p's: 0.641243 runs down; ks test for 10 p's: 0.740136 |-------------------------------------------------------------| |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 out No. of wins: Observed Expected 98775 98585.858586 z-score= 0.846, pvalue=0.19879 Analysis of Throws-per-Game: Throws Observed Expected Chisq Sum of (O-E)^2/E 1 66710 66666.7 0.028 0.028 2 37450 37654.3 1.109 1.137 3 27039 26954.7 0.263 1.400 4 19373 19313.5 0.184 1.584 5 13941 13851.4 0.579 2.163 6 9756 9943.5 3.537 5.700 7 7169 7145.0 0.080 5.781 8 5127 5139.1 0.028 5.809 9 3806 3699.9 3.045 8.854 10 2731 2666.3 1.570 10.424 11 1881 1923.3 0.932 11.356 12 1379 1388.7 0.068 11.424 13 1017 1003.7 0.176 11.600 14 728 726.1 0.005 11.604 15 471 525.8 5.718 17.323 16 366 381.2 0.602 17.925 17 279 276.5 0.022 17.947 18 205 200.8 0.087 18.034 19 148 146.0 0.028 18.061 20 114 106.2 0.571 18.632 21 310 287.1 1.824 20.456 Chisq= 20.46 for 20 degrees of freedom, p= 0.42973 SUMMARY of craptest on out p-value for no. of wins: 0.198790 p-value for throws/game: 0.429734 _____________________________________________________________ bash2-2.05b$ exit Script done on Wed Nov 22 10:53:55 2006