seededRandom is not random at all.

These are old bug reports that have been closed.
User avatar
pixelfck
Militia Captain
Militia Captain
Posts: 571
Joined: Tue Aug 11, 2009 8:47 pm
Location: Travelling around in Europe

Thu Oct 10, 2013 12:22 pm

I tried to use (seededRandom ...) with varying seed values as a replacement for (random ...). It however turns out that the output generated by (seededRandom ...) is not as random as one might come to expect from the function name.

The below code sample clearly shows the pattern:

Code: Select all

(block (nodes i)
	(for i 20 50
		(dbgLog "(seededRandom " i " 0 100): " (seededRandom i 0 100))
		)
	)

10/10/2013 13:58:23	(seededRandom 20 0 100): 2
10/10/2013 13:58:23	(seededRandom 21 0 100): 6
10/10/2013 13:58:23	(seededRandom 22 0 100): 9
10/10/2013 13:58:23	(seededRandom 23 0 100): 12
10/10/2013 13:58:23	(seededRandom 24 0 100): 15
10/10/2013 13:58:23	(seededRandom 25 0 100): 19
10/10/2013 13:58:23	(seededRandom 26 0 100): 22
10/10/2013 13:58:23	(seededRandom 27 0 100): 25
10/10/2013 13:58:23	(seededRandom 28 0 100): 29
10/10/2013 13:58:23	(seededRandom 29 0 100): 32
10/10/2013 13:58:23	(seededRandom 30 0 100): 35
10/10/2013 13:58:23	(seededRandom 31 0 100): 38
10/10/2013 13:58:23	(seededRandom 32 0 100): 42
10/10/2013 13:58:23	(seededRandom 33 0 100): 45
10/10/2013 13:58:23	(seededRandom 34 0 100): 48
10/10/2013 13:58:23	(seededRandom 35 0 100): 51
10/10/2013 13:58:23	(seededRandom 36 0 100): 55
10/10/2013 13:58:23	(seededRandom 37 0 100): 58
10/10/2013 13:58:23	(seededRandom 38 0 100): 61
10/10/2013 13:58:23	(seededRandom 39 0 100): 64
10/10/2013 13:58:23	(seededRandom 40 0 100): 68
10/10/2013 13:58:23	(seededRandom 41 0 100): 71
10/10/2013 13:58:23	(seededRandom 42 0 100): 74
10/10/2013 13:58:23	(seededRandom 43 0 100): 78
10/10/2013 13:58:23	(seededRandom 44 0 100): 81
10/10/2013 13:58:23	(seededRandom 45 0 100): 84
10/10/2013 13:58:23	(seededRandom 46 0 100): 87
10/10/2013 13:58:23	(seededRandom 47 0 100): 91
10/10/2013 13:58:23	(seededRandom 48 0 100): 94
10/10/2013 13:58:23	(seededRandom 49 0 100): 97
10/10/2013 13:58:23	(seededRandom 50 0 100): 100
As you can see, a larger seed value results in a larger output value.

~ Pixelfck
Image
Download the Black Market Expansion from Xelerus.de today!
My other mods at xelerus.de

george moromisato
Developer
Developer
Posts: 2875
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

Thu Oct 10, 2013 3:08 pm

I'm reminded of this XKCD

Image

I agree that I need a better algorithm. Can anyone suggest a good one for this purpose?

User avatar
Wolfy
Fleet Admiral
Fleet Admiral
Posts: 5351
Joined: Tue Feb 05, 2008 1:10 am
Location: Somewhere in the Frontier on a Hycrotan station, working on new ships.

Thu Oct 10, 2013 3:12 pm

Wouldnt the default C one be sufficient (it has a method to seed it)? Another possibility is to simply toss it into MD5
(shpOrder gPlayership 'barrelRoll)
(plySetGenome gPlayer (list 'hycrotan 'nonBinary))
Image

User avatar
pixelfck
Militia Captain
Militia Captain
Posts: 571
Joined: Tue Aug 11, 2009 8:47 pm
Location: Travelling around in Europe

Thu Oct 10, 2013 4:16 pm

Creating (pseudo) random numbers is tricky business; one of those common much-harder-than-you-would-expect problems. So I would advice against inventing your own wheel here.

For high quality random pseudo random integers I would recommend the Mersenne twister (wikipedia even has pseudo code desribing the algorithm).
However generating cryptography quality randomness would probably be an overkill for Transcendence. So you could take a look at the more common Linear congruential generator which is fast and easy to implement(and source code examples should be easy to find).

Cheers
Pixelfck
Image
Download the Black Market Expansion from Xelerus.de today!
My other mods at xelerus.de

User avatar
Wolfy
Fleet Admiral
Fleet Admiral
Posts: 5351
Joined: Tue Feb 05, 2008 1:10 am
Location: Somewhere in the Frontier on a Hycrotan station, working on new ships.

Thu Oct 10, 2013 4:21 pm

seededRandom just needs to use anything deterministic (because its seeded) with a decent distribution of randomness - and yes, cryptographically secure prngs would be overkill.
(shpOrder gPlayership 'barrelRoll)
(plySetGenome gPlayer (list 'hycrotan 'nonBinary))
Image

User avatar
digdug
Fleet Admiral
Fleet Admiral
Posts: 2600
Joined: Mon Oct 29, 2007 9:23 pm
Location: Decoding hieroglyphics on Tan-Ru-Dorem

Thu Oct 10, 2013 4:24 pm

seededRandom is not random, because it uses a seed, of course.

what about using an old BASIC trick ?
use unvGetTick and unvGetRealDate as seeds or some linear combinations of those two functions to generate unique seeds every time.

User avatar
Wolfy
Fleet Admiral
Fleet Admiral
Posts: 5351
Joined: Tue Feb 05, 2008 1:10 am
Location: Somewhere in the Frontier on a Hycrotan station, working on new ships.

Thu Oct 10, 2013 4:31 pm

We dont want it to be truly random - it needs to be deterministic based on the seed put in (and time based prngs arent truly random I know, but it prevents doing something like world generation seeds, as seen in say, minecraft)
IE, (seededRandom i 0 99) should do something like this:

first time a loop is run
...
i = 45 >> 56
i = 46 >> 74
i = 47 >> 29
...

second time
...
i = 45 >> 56
i = 46 >> 74
i = 47 >> 29
...

third time
...
i = 45 >> 56
i = 46 >> 74
i = 47 >> 29
...
(shpOrder gPlayership 'barrelRoll)
(plySetGenome gPlayer (list 'hycrotan 'nonBinary))
Image

george moromisato
Developer
Developer
Posts: 2875
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

Thu Oct 10, 2013 4:33 pm

pixelfck wrote:Creating (pseudo) random numbers is tricky business; one of those common much-harder-than-you-would-expect problems. So I would advice against inventing your own wheel here.

For high quality random pseudo random integers I would recommend the Mersenne twister (wikipedia even has pseudo code desribing the algorithm).
However generating cryptography quality randomness would probably be an overkill for Transcendence. So you could take a look at the more common Linear congruential generator which is fast and easy to implement(and source code examples should be easy to find).

Cheers
Pixelfck
For normal randomness I'm currently using one derived from this paper (http://www.academia.edu/894176/Random_n ... rd_to_find). It's an older algorithm, and I probably should move to the Mersenne Twister, but I doubt that anyone would notice the difference.

For the seededRandom function, though, I tried to adapt the standard C runtime algorithm. I need to go back and revisit it.

Depending on your needs you might be better off with the objGetDestiny value. Every object (ship, station, etc.) gets a random number from 0-359 assigned at creation. You can use that for persistent randomness. [Though its limited range makes it useful for only small choices.]

User avatar
Atarlost
Fleet Admiral
Fleet Admiral
Posts: 2391
Joined: Tue Aug 26, 2008 12:02 am

Thu Oct 10, 2013 4:42 pm

Using a high quality RNG probably won't compare to the work involved in switching to an interpreted language all the time to run scripts.

Mersenne twisters apparently make horrible seeded RNGs since they need a noisy input to work well.

The standard C runtime algorithm is horrible. It'd probably be okay for minor stuff like weapon damage, but it's not good for system or loot generation or for handing to a script where you don't know what it might be used for.
Literally is the new Figuratively

User avatar
Wolfy
Fleet Admiral
Fleet Admiral
Posts: 5351
Joined: Tue Feb 05, 2008 1:10 am
Location: Somewhere in the Frontier on a Hycrotan station, working on new ships.

Thu Oct 10, 2013 6:03 pm

http://stat.fsu.edu/pub/diehard/

Apparently those tests are popular for checking randomness of RNGs.

(and remember that that odds are that for enough tests run, you will occasionally just get random numbers that randomly happen to coincide. Its when after a sufficient number of tests that it always ends up with patterns that you have a problem - so if a single test shows that its not looking random, test at least several more times.)
(shpOrder gPlayership 'barrelRoll)
(plySetGenome gPlayer (list 'hycrotan 'nonBinary))
Image

User avatar
pixelfck
Militia Captain
Militia Captain
Posts: 571
Joined: Tue Aug 11, 2009 8:47 pm
Location: Travelling around in Europe

Fri Oct 11, 2013 9:46 am

Atarlost wrote:Mersenne twisters apparently make horrible seeded RNGs since they need a noisy input to work well.
I should have looked that up before I posted it. I just knew it was thought high of by the cryptographers, but I guess they use a high entropy seed.

*Edit* Oh damn, now I'm interested in yet another set of algorithms.
Image
Download the Black Market Expansion from Xelerus.de today!
My other mods at xelerus.de

User avatar
pixelfck
Militia Captain
Militia Captain
Posts: 571
Joined: Tue Aug 11, 2009 8:47 pm
Location: Travelling around in Europe

Fri Oct 11, 2013 8:11 pm

I did some reading and experimenting with simple hash functions to generate the consistent random output based on a seed.

I came up with the following (in javascript):

Code: Select all

var seededRandom = function(seed, from, to) {
	var a = 1103515245;
	var c = 12345;
	var range, random;
	
	seed = a * seed + c;
	random = seed ^ (seed >> 11) ^ (seed << 5) & (seed >> 7) ^ (seed << 3) ^ (seed >> 13);
	range = to - from;
	return from + (Math.abs(random) % range);
};
This generates an integer value, ranging from the 'from'-argument up to (but not including) the 'to'-argument, based on the seed (an integer).

So, the big question is off course, how good is the resulting randomness.
Some pictures: Image

The image shows 3 separate methods: the first being 6000 samples from the javascript native implementation Math.random(), the second is the method is the output from the algorithm described above, with a sequential seed value ranging from 0 to 6000. The final image is generated with 6000 samples truly random noise obtained from www.random.org.

The above images give a reasonable indication of how good the randomness is, any big biases would show up as a recognizable pattern. Since there is no real pattern visible (at least to my eye) I conclude that the resulting randomness is probably good enough for Transcendence.

Disclaimer: the above algorithm is exactly what I advised against earlier: I invented my own wheel here. I did not do any formal statistical analysis on it and yet I claim it is 'good enough' based on some visual clues. So: use at your own risk.

Cheers,
Pixelfck
Image
Download the Black Market Expansion from Xelerus.de today!
My other mods at xelerus.de

george moromisato
Developer
Developer
Posts: 2875
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

Fri Oct 11, 2013 11:06 pm

pixelfck wrote:I did some reading and experimenting with simple hash functions to generate the consistent random output based on a seed...
That's really awesome.

What algorithm did you use to generate the charts? Did you just use a random number for x and y coordinates and plot it?

User avatar
Wolfy
Fleet Admiral
Fleet Admiral
Posts: 5351
Joined: Tue Feb 05, 2008 1:10 am
Location: Somewhere in the Frontier on a Hycrotan station, working on new ships.

Sat Oct 12, 2013 2:12 am

if you're using integers, watch out for overlaps

in other news I created an rng of my own for fun which passed the diehard test suite. Its slow, but that might have just been disk io.

This weekend I may be making a Mk.II version of it which will incorporate some cryptosecurity. Even though its completely pointless for this, its more for my own entertainment.

I might not post the code till later or something.

Code: Select all

       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=F(X), where F is the assumed distribution of the sample                
       random variable X---often normal. But that assumed F is just             
       an asymptotic approximation, for which the fit will be worst             
       in the tails. Thus you should not be surprised with                      
       occasional 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 RNG's.  So keep in mind that " p happens".                     
     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::        
     ::            This is the BIRTHDAY SPACINGS TEST                 ::        
     :: Choose m birthdays in a year of n days.  List the spacings    ::        
     :: between the birthdays.  If j is 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^9,  so that the underlying distribution for j  ::        
     :: is taken to be Poisson with lambda=2^27/(2^26)=2.  A sample   ::        
     :: of 500 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. Next, bits 2-25 are   ::        
     :: used to provide birthdays, then 3-26 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.                                ::        
     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::        
 BIRTHDAY SPACINGS TEST, M= 512 N=2**24 LAMBDA=  2.0000
           Results for out.rbnf       
                   For a sample of size 500:     mean   
           out.rbnf        using bits  1 to 24   1.956
  duplicate       number       number 
  spacings       observed     expected
        0          62.       67.668
        1         151.      135.335
        2         126.      135.335
        3          94.       90.224
        4          47.       45.112
        5          16.       18.045
  6 to INF          4.        8.282
 Chisquare with  6 d.o.f. =     5.61 p-value=  .532255
  :::::::::::::::::::::::::::::::::::::::::
                   For a sample of size 500:     mean   
           out.rbnf        using bits  2 to 25   2.012
  duplicate       number       number 
  spacings       observed     expected
        0          64.       67.668
        1         140.      135.335
        2         130.      135.335
        3          90.       90.224
        4          53.       45.112
        5          15.       18.045
  6 to INF          8.        8.282
 Chisquare with  6 d.o.f. =     2.47 p-value=  .128536
  :::::::::::::::::::::::::::::::::::::::::
                   For a sample of size 500:     mean   
           out.rbnf        using bits  3 to 26   1.922
  duplicate       number       number 
  spacings       observed     expected
        0          72.       67.668
        1         147.      135.335
        2         128.      135.335
        3          83.       90.224
        4          46.       45.112
        5          20.       18.045
  6 to INF          4.        8.282
 Chisquare with  6 d.o.f. =     4.70 p-value=  .417412
  :::::::::::::::::::::::::::::::::::::::::
                   For a sample of size 500:     mean   
           out.rbnf        using bits  4 to 27   1.918
  duplicate       number       number 
  spacings       observed     expected
        0          73.       67.668
        1         138.      135.335
        2         135.      135.335
        3          97.       90.224
        4          32.       45.112
        5          20.       18.045
  6 to INF          5.        8.282
 Chisquare with  6 d.o.f. =     6.31 p-value=  .610175
  :::::::::::::::::::::::::::::::::::::::::
                   For a sample of size 500:     mean   
           out.rbnf        using bits  5 to 28   2.098
  duplicate       number       number 
  spacings       observed     expected
        0          73.       67.668
        1         122.      135.335
        2         121.      135.335
        3          96.       90.224
        4          58.       45.112
        5          21.       18.045
  6 to INF          9.        8.282
 Chisquare with  6 d.o.f. =     7.85 p-value=  .750767
  :::::::::::::::::::::::::::::::::::::::::
                   For a sample of size 500:     mean   
           out.rbnf        using bits  6 to 29   1.990
  duplicate       number       number 
  spacings       observed     expected
        0          67.       67.668
        1         150.      135.335
        2         122.      135.335
        3          86.       90.224
        4          45.       45.112
        5          19.       18.045
  6 to INF         11.        8.282
 Chisquare with  6 d.o.f. =     4.05 p-value=  .330135
  :::::::::::::::::::::::::::::::::::::::::
                   For a sample of size 500:     mean   
           out.rbnf        using bits  7 to 30   1.972
  duplicate       number       number 
  spacings       observed     expected
        0          73.       67.668
        1         115.      135.335
        2         159.      135.335
        3          82.       90.224
        4          53.       45.112
        5          14.       18.045
  6 to INF          4.        8.282
 Chisquare with  6 d.o.f. =    12.86 p-value=  .954736
  :::::::::::::::::::::::::::::::::::::::::
                   For a sample of size 500:     mean   
           out.rbnf        using bits  8 to 31   2.024
  duplicate       number       number 
  spacings       observed     expected
        0          60.       67.668
        1         134.      135.335
        2         140.      135.335
        3          98.       90.224
        4          43.       45.112
        5          19.       18.045
  6 to INF          6.        8.282
 Chisquare with  6 d.o.f. =     2.49 p-value=  .130547
  :::::::::::::::::::::::::::::::::::::::::
                   For a sample of size 500:     mean   
           out.rbnf        using bits  9 to 32   2.070
  duplicate       number       number 
  spacings       observed     expected
        0          59.       67.668
        1         138.      135.335
        2         130.      135.335
        3         103.       90.224
        4          37.       45.112
        5          22.       18.045
  6 to INF         11.        8.282
 Chisquare with  6 d.o.f. =     6.40 p-value=  .620102
  :::::::::::::::::::::::::::::::::::::::::
   The 9 p-values were
        .532255   .128536   .417412   .610175   .750767
        .330135   .954736   .130547   .620102
  A KSTEST for the 9 p-values yields  .035832

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::        
     ::            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 out.rbnf       
     For a sample of 1,000,000 consecutive 5-tuples,
 chisquare for 99 degrees of freedom=114.026; p-value= .856642
           OPERM5 test for file out.rbnf       
     For a sample of 1,000,000 consecutive 5-tuples,
 chisquare for 99 degrees of freedom=125.500; p-value= .962777
     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::        
     :: 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 chisqua-::        
     :: re test is performed on counts for ranks 31,30,29 and <=28.   ::        
     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::        
    Binary rank test for out.rbnf       
         Rank test for 31x31 binary matrices:
        rows from leftmost 31 bits of each 32-bit integer
      rank   observed  expected (o-e)^2/e  sum
        28       219     211.4   .271909     .272
        29      5145    5134.0   .023524     .295
        30     23018   23103.0   .313074     .609
        31     11618   11551.5   .382547     .991
  chisquare=  .991 for 3 d. of f.; p-value= .356326
--------------------------------------------------------------
     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::        
     :: 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.                                                  ::        
     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::        
    Binary rank test for out.rbnf       
         Rank test for 32x32 binary matrices:
        rows from leftmost 32 bits of each 32-bit integer
      rank   observed  expected (o-e)^2/e  sum
        29       210     211.4   .009511     .010
        30      5197    5134.0   .772828     .782
        31     22977   23103.0   .687693    1.470
        32     11616   11551.5   .359875    1.830
  chisquare= 1.830 for 3 d. of f.; p-value= .479621
--------------------------------------------------------------

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::        
     :: 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 <=4.                                 ::        
     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::        
         Binary Rank Test for out.rbnf       
        Rank of a 6x8 binary matrix,
     rows formed from eight bits of the RNG out.rbnf       
     b-rank test for bits  1 to  8
                     OBSERVED   EXPECTED     (O-E)^2/E      SUM
          r<=4          974       944.3        .934        .934
          r =5        21965     21743.9       2.248       3.182
          r =6        77061     77311.8        .814       3.996
                        p=1-exp(-SUM/2)= .86439
        Rank of a 6x8 binary matrix,
     rows formed from eight bits of the RNG out.rbnf       
     b-rank test for bits  2 to  9
                     OBSERVED   EXPECTED     (O-E)^2/E      SUM
          r<=4          982       944.3       1.505       1.505
          r =5        21927     21743.9       1.542       3.047
          r =6        77091     77311.8        .631       3.677
                        p=1-exp(-SUM/2)= .84098
        Rank of a 6x8 binary matrix,
     rows formed from eight bits of the RNG out.rbnf       
     b-rank test for bits  3 to 10
                     OBSERVED   EXPECTED     (O-E)^2/E      SUM
          r<=4          913       944.3       1.038       1.038
          r =5        21787     21743.9        .085       1.123
          r =6        77300     77311.8        .002       1.125
                        p=1-exp(-SUM/2)= .43016
        Rank of a 6x8 binary matrix,
     rows formed from eight bits of the RNG out.rbnf       
     b-rank test for bits  4 to 11
                     OBSERVED   EXPECTED     (O-E)^2/E      SUM
          r<=4          953       944.3        .080        .080
          r =5        21708     21743.9        .059        .139
          r =6        77339     77311.8        .010        .149
                        p=1-exp(-SUM/2)= .07178
        Rank of a 6x8 binary matrix,
     rows formed from eight bits of the RNG out.rbnf       
     b-rank test for bits  5 to 12
                     OBSERVED   EXPECTED     (O-E)^2/E      SUM
          r<=4          964       944.3        .411        .411
          r =5        21655     21743.9        .363        .774
          r =6        77381     77311.8        .062        .836
                        p=1-exp(-SUM/2)= .34175
        Rank of a 6x8 binary matrix,
     rows formed from eight bits of the RNG out.rbnf       
     b-rank test for bits  6 to 13
                     OBSERVED   EXPECTED     (O-E)^2/E      SUM
          r<=4          901       944.3       1.986       1.986
          r =5        21958     21743.9       2.108       4.094
          r =6        77141     77311.8        .377       4.471
                        p=1-exp(-SUM/2)= .89306
        Rank of a 6x8 binary matrix,
     rows formed from eight bits of the RNG out.rbnf       
     b-rank test for bits  7 to 14
                     OBSERVED   EXPECTED     (O-E)^2/E      SUM
          r<=4          927       944.3        .317        .317
          r =5        21732     21743.9        .007        .324
          r =6        77341     77311.8        .011        .335
                        p=1-exp(-SUM/2)= .15402
        Rank of a 6x8 binary matrix,
     rows formed from eight bits of the RNG out.rbnf       
     b-rank test for bits  8 to 15
                     OBSERVED   EXPECTED     (O-E)^2/E      SUM
          r<=4          933       944.3        .135        .135
          r =5        21741     21743.9        .000        .136
          r =6        77326     77311.8        .003        .138
                        p=1-exp(-SUM/2)= .06679
        Rank of a 6x8 binary matrix,
     rows formed from eight bits of the RNG out.rbnf       
     b-rank test for bits  9 to 16
                     OBSERVED   EXPECTED     (O-E)^2/E      SUM
          r<=4          928       944.3        .281        .281
          r =5        21799     21743.9        .140        .421
          r =6        77273     77311.8        .019        .441
                        p=1-exp(-SUM/2)= .19768
        Rank of a 6x8 binary matrix,
     rows formed from eight bits of the RNG out.rbnf       
     b-rank test for bits 10 to 17
                     OBSERVED   EXPECTED     (O-E)^2/E      SUM
          r<=4          939       944.3        .030        .030
          r =5        21739     21743.9        .001        .031
          r =6        77322     77311.8        .001        .032
                        p=1-exp(-SUM/2)= .01598
        Rank of a 6x8 binary matrix,
     rows formed from eight bits of the RNG out.rbnf       
     b-rank test for bits 11 to 18
                     OBSERVED   EXPECTED     (O-E)^2/E      SUM
          r<=4          862       944.3       7.173       7.173
          r =5        21905     21743.9       1.194       8.367
          r =6        77233     77311.8        .080       8.447
                        p=1-exp(-SUM/2)= .98535
        Rank of a 6x8 binary matrix,
     rows formed from eight bits of the RNG out.rbnf       
     b-rank test for bits 12 to 19
                     OBSERVED   EXPECTED     (O-E)^2/E      SUM
          r<=4          909       944.3       1.320       1.320
          r =5        21808     21743.9        .189       1.509
          r =6        77283     77311.8        .011       1.519
                        p=1-exp(-SUM/2)= .53219
        Rank of a 6x8 binary matrix,
     rows formed from eight bits of the RNG out.rbnf       
     b-rank test for bits 13 to 20
                     OBSERVED   EXPECTED     (O-E)^2/E      SUM
          r<=4          949       944.3        .023        .023
          r =5        21614     21743.9        .776        .799
          r =6        77437     77311.8        .203       1.002
                        p=1-exp(-SUM/2)= .39412
        Rank of a 6x8 binary matrix,
     rows formed from eight bits of the RNG out.rbnf       
     b-rank test for bits 14 to 21
                     OBSERVED   EXPECTED     (O-E)^2/E      SUM
          r<=4          941       944.3        .012        .012
          r =5        21603     21743.9        .913        .925
          r =6        77456     77311.8        .269       1.194
                        p=1-exp(-SUM/2)= .44941
        Rank of a 6x8 binary matrix,
     rows formed from eight bits of the RNG out.rbnf       
     b-rank test for bits 15 to 22
                     OBSERVED   EXPECTED     (O-E)^2/E      SUM
          r<=4          975       944.3        .998        .998
          r =5        21643     21743.9        .468       1.466
          r =6        77382     77311.8        .064       1.530
                        p=1-exp(-SUM/2)= .53465
        Rank of a 6x8 binary matrix,
     rows formed from eight bits of the RNG out.rbnf       
     b-rank test for bits 16 to 23
                     OBSERVED   EXPECTED     (O-E)^2/E      SUM
          r<=4          935       944.3        .092        .092
          r =5        21697     21743.9        .101        .193
          r =6        77368     77311.8        .041        .234
                        p=1-exp(-SUM/2)= .11025
        Rank of a 6x8 binary matrix,
     rows formed from eight bits of the RNG out.rbnf       
     b-rank test for bits 17 to 24
                     OBSERVED   EXPECTED     (O-E)^2/E      SUM
          r<=4          953       944.3        .080        .080
          r =5        21560     21743.9       1.555       1.635
          r =6        77487     77311.8        .397       2.032
                        p=1-exp(-SUM/2)= .63805
        Rank of a 6x8 binary matrix,
     rows formed from eight bits of the RNG out.rbnf       
     b-rank test for bits 18 to 25
                     OBSERVED   EXPECTED     (O-E)^2/E      SUM
          r<=4         1032       944.3       8.145       8.145
          r =5        21438     21743.9       4.304      12.448
          r =6        77530     77311.8        .616      13.064
                        p=1-exp(-SUM/2)= .99854
        Rank of a 6x8 binary matrix,
     rows formed from eight bits of the RNG out.rbnf       
     b-rank test for bits 19 to 26
                     OBSERVED   EXPECTED     (O-E)^2/E      SUM
          r<=4          981       944.3       1.426       1.426
          r =5        21415     21743.9       4.975       6.401
          r =6        77604     77311.8       1.104       7.506
                        p=1-exp(-SUM/2)= .97655
        Rank of a 6x8 binary matrix,
     rows formed from eight bits of the RNG out.rbnf       
     b-rank test for bits 20 to 27
                     OBSERVED   EXPECTED     (O-E)^2/E      SUM
          r<=4          956       944.3        .145        .145
          r =5        21755     21743.9        .006        .151
          r =6        77289     77311.8        .007        .157
                        p=1-exp(-SUM/2)= .07565
        Rank of a 6x8 binary matrix,
     rows formed from eight bits of the RNG out.rbnf       
     b-rank test for bits 21 to 28
                     OBSERVED   EXPECTED     (O-E)^2/E      SUM
          r<=4          981       944.3       1.426       1.426
          r =5        21772     21743.9        .036       1.463
          r =6        77247     77311.8        .054       1.517
                        p=1-exp(-SUM/2)= .53160
        Rank of a 6x8 binary matrix,
     rows formed from eight bits of the RNG out.rbnf       
     b-rank test for bits 22 to 29
                     OBSERVED   EXPECTED     (O-E)^2/E      SUM
          r<=4          919       944.3        .678        .678
          r =5        21687     21743.9        .149        .827
          r =6        77394     77311.8        .087        .914
                        p=1-exp(-SUM/2)= .36688
        Rank of a 6x8 binary matrix,
     rows formed from eight bits of the RNG out.rbnf       
     b-rank test for bits 23 to 30
                     OBSERVED   EXPECTED     (O-E)^2/E      SUM
          r<=4          957       944.3        .171        .171
          r =5        21925     21743.9       1.508       1.679
          r =6        77118     77311.8        .486       2.165
                        p=1-exp(-SUM/2)= .66124
        Rank of a 6x8 binary matrix,
     rows formed from eight bits of the RNG out.rbnf       
     b-rank test for bits 24 to 31
                     OBSERVED   EXPECTED     (O-E)^2/E      SUM
          r<=4          905       944.3       1.636       1.636
          r =5        21705     21743.9        .070       1.705
          r =6        77390     77311.8        .079       1.784
                        p=1-exp(-SUM/2)= .59024
        Rank of a 6x8 binary matrix,
     rows formed from eight bits of the RNG out.rbnf       
     b-rank test for bits 25 to 32
                     OBSERVED   EXPECTED     (O-E)^2/E      SUM
          r<=4          954       944.3        .100        .100
          r =5        21727     21743.9        .013        .113
          r =6        77319     77311.8        .001        .113
                        p=1-exp(-SUM/2)= .05513
   TEST SUMMARY, 25 tests on 100,000 random 6x8 matrices
 These should be 25 uniform [0,1] random variables:
     .864386     .840982     .430158     .071779     .341746
     .893065     .154024     .066788     .197684     .015976
     .985352     .532188     .394123     .449406     .534655
     .110248     .638048     .998544     .976547     .075648
     .531601     .366883     .661241     .590242     .055132
   brank test summary for out.rbnf       
       The KS test for those 25 supposed UNI's yields
                    KS p-value= .600076

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::        
     ::                   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, 20 BITS PER WORD, N words
   This test uses N=2^21 and samples the bitstream 20 times.
  No. missing words should average  141909. with sigma=428.
---------------------------------------------------------
 tst no  1:  141555 missing words,    -.83 sigmas from mean, p-value= .20387
 tst no  2:  142071 missing words,     .38 sigmas from mean, p-value= .64719
 tst no  3:  141695 missing words,    -.50 sigmas from mean, p-value= .30827
 tst no  4:  142034 missing words,     .29 sigmas from mean, p-value= .61458
 tst no  5:  142214 missing words,     .71 sigmas from mean, p-value= .76172
 tst no  6:  141580 missing words,    -.77 sigmas from mean, p-value= .22081
 tst no  7:  141834 missing words,    -.18 sigmas from mean, p-value= .43015
 tst no  8:  142246 missing words,     .79 sigmas from mean, p-value= .78425
 tst no  9:  141437 missing words,   -1.10 sigmas from mean, p-value= .13489
 tst no 10:  141594 missing words,    -.74 sigmas from mean, p-value= .23064
 tst no 11:  142004 missing words,     .22 sigmas from mean, p-value= .58753
 tst no 12:  141682 missing words,    -.53 sigmas from mean, p-value= .29766
 tst no 13:  142477 missing words,    1.33 sigmas from mean, p-value= .90764
 tst no 14:  142024 missing words,     .27 sigmas from mean, p-value= .60562
 tst no 15:  141263 missing words,   -1.51 sigmas from mean, p-value= .06551
 tst no 16:  141971 missing words,     .14 sigmas from mean, p-value= .55729
 tst no 17:  141997 missing words,     .20 sigmas from mean, p-value= .58115
 tst no 18:  141865 missing words,    -.10 sigmas from mean, p-value= .45876
 tst no 19:  141518 missing words,    -.91 sigmas from mean, p-value= .18027
 tst no 20:  142365 missing words,    1.06 sigmas from mean, p-value= .85648

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::        
     ::             The tests OPSO, OQSO and DNA                      ::        
     ::         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.                                  ::        
     ::                                                               ::        
     ::     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.                                         ::        
     ::                                                               ::        
     ::    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.                  ::        
     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::        
 OPSO test for generator out.rbnf       
  Output: No. missing words (mw), equiv normal variate (z), p-value (p)
                                                           mw     z     p
    OPSO for out.rbnf        using bits 23 to 32        141844  -.225  .4109
    OPSO for out.rbnf        using bits 22 to 31        141567 -1.180  .1189
    OPSO for out.rbnf        using bits 21 to 30        141478 -1.487  .0685
    OPSO for out.rbnf        using bits 20 to 29        141684  -.777  .2186
    OPSO for out.rbnf        using bits 19 to 28        142069   .551  .7090
    OPSO for out.rbnf        using bits 18 to 27        142059   .516  .6971
    OPSO for out.rbnf        using bits 17 to 26        142437  1.820  .9656
    OPSO for out.rbnf        using bits 16 to 25        141817  -.318  .3751
    OPSO for out.rbnf        using bits 15 to 24        142181   .937  .8256
    OPSO for out.rbnf        using bits 14 to 23        142029   .413  .6601
    OPSO for out.rbnf        using bits 13 to 22        141912   .009  .5037
    OPSO for out.rbnf        using bits 12 to 21        141791  -.408  .3416
    OPSO for out.rbnf        using bits 11 to 20        141405 -1.739  .0410
    OPSO for out.rbnf        using bits 10 to 19        142316  1.402  .9196
    OPSO for out.rbnf        using bits  9 to 18        142224  1.085  .8611
    OPSO for out.rbnf        using bits  8 to 17        142290  1.313  .9054
    OPSO for out.rbnf        using bits  7 to 16        141758  -.522  .3009
    OPSO for out.rbnf        using bits  6 to 15        141869  -.139  .4447
    OPSO for out.rbnf        using bits  5 to 14        141432 -1.646  .0499
    OPSO for out.rbnf        using bits  4 to 13        142339  1.482  .9308
    OPSO for out.rbnf        using bits  3 to 12        142200  1.002  .8419
    OPSO for out.rbnf        using bits  2 to 11        141717  -.663  .2536
    OPSO for out.rbnf        using bits  1 to 10        141861  -.167  .4338
 OQSO test for generator out.rbnf       
  Output: No. missing words (mw), equiv normal variate (z), p-value (p)
                                                           mw     z     p
    OQSO for out.rbnf        using bits 28 to 32        141914   .016  .5063
    OQSO for out.rbnf        using bits 27 to 31        142180   .918  .8206
    OQSO for out.rbnf        using bits 26 to 30        141978   .233  .5920
    OQSO for out.rbnf        using bits 25 to 29        141969   .202  .5802
    OQSO for out.rbnf        using bits 24 to 28        142049   .473  .6821
    OQSO for out.rbnf        using bits 23 to 27        142674  2.592  .9952
    OQSO for out.rbnf        using bits 22 to 26        141602 -1.042  .1488
    OQSO for out.rbnf        using bits 21 to 25        141778  -.445  .3281
    OQSO for out.rbnf        using bits 20 to 24        141826  -.282  .3888
    OQSO for out.rbnf        using bits 19 to 23        141914   .016  .5063
    OQSO for out.rbnf        using bits 18 to 22        141345 -1.913  .0279
    OQSO for out.rbnf        using bits 17 to 21        141763  -.496  .3099
    OQSO for out.rbnf        using bits 16 to 20        141615  -.998  .1592
    OQSO for out.rbnf        using bits 15 to 19        141833  -.259  .3979
    OQSO for out.rbnf        using bits 14 to 18        142166   .870  .8079
    OQSO for out.rbnf        using bits 13 to 17        141690  -.743  .2286
    OQSO for out.rbnf        using bits 12 to 16        142088   .606  .7276
    OQSO for out.rbnf        using bits 11 to 15        141678  -.784  .2165
    OQSO for out.rbnf        using bits 10 to 14        142464  1.880  .9700
    OQSO for out.rbnf        using bits  9 to 13        141819  -.306  .3797
    OQSO for out.rbnf        using bits  8 to 12        142367  1.551  .9396
    OQSO for out.rbnf        using bits  7 to 11        141728  -.615  .2694
    OQSO for out.rbnf        using bits  6 to 10        141852  -.194  .4230
    OQSO for out.rbnf        using bits  5 to  9        141142 -2.601  .0046
    OQSO for out.rbnf        using bits  4 to  8        141660  -.845  .1990
    OQSO for out.rbnf        using bits  3 to  7        142461  1.870  .9693
    OQSO for out.rbnf        using bits  2 to  6        141527 -1.296  .0975
    OQSO for out.rbnf        using bits  1 to  5        140895 -3.438  .0003
  DNA test for generator out.rbnf       
  Output: No. missing words (mw), equiv normal variate (z), p-value (p)
                                                           mw     z     p
     DNA for out.rbnf        using bits 31 to 32        141680  -.676  .2494
     DNA for out.rbnf        using bits 30 to 31        141648  -.771  .2204
     DNA for out.rbnf        using bits 29 to 30        141800  -.323  .3735
     DNA for out.rbnf        using bits 28 to 29        141441 -1.381  .0836
     DNA for out.rbnf        using bits 27 to 28        141538 -1.095  .1367
     DNA for out.rbnf        using bits 26 to 27        142103   .571  .7161
     DNA for out.rbnf        using bits 25 to 26        141927   .052  .5208
     DNA for out.rbnf        using bits 24 to 25        141775  -.396  .3460
     DNA for out.rbnf        using bits 23 to 24        142223   .925  .8226
     DNA for out.rbnf        using bits 22 to 23        141624  -.842  .2000
     DNA for out.rbnf        using bits 21 to 22        141302 -1.792  .0366
     DNA for out.rbnf        using bits 20 to 21        142011   .300  .6179
     DNA for out.rbnf        using bits 19 to 20        142097   .554  .7101
     DNA for out.rbnf        using bits 18 to 19        141827  -.243  .4041
     DNA for out.rbnf        using bits 17 to 18        142012   .303  .6190
     DNA for out.rbnf        using bits 16 to 17        141688  -.653  .2569
     DNA for out.rbnf        using bits 15 to 16        141552 -1.054  .1459
     DNA for out.rbnf        using bits 14 to 15        141897  -.036  .4855
     DNA for out.rbnf        using bits 13 to 14        142193   .837  .7986
     DNA for out.rbnf        using bits 12 to 13        141740  -.499  .3087
     DNA for out.rbnf        using bits 11 to 12        141321 -1.735  .0413
     DNA for out.rbnf        using bits 10 to 11        141919   .029  .5114
     DNA for out.rbnf        using bits  9 to 10        142185   .813  .7919
     DNA for out.rbnf        using bits  8 to  9        141429 -1.417  .0783
     DNA for out.rbnf        using bits  7 to  8        142380  1.388  .9175
     DNA for out.rbnf        using bits  6 to  7        141358 -1.626  .0519
     DNA for out.rbnf        using bits  5 to  6        141787  -.361  .3591
     DNA for out.rbnf        using bits  4 to  5        141436 -1.396  .0813
     DNA for out.rbnf        using bits  3 to  4        141771  -.408  .3416
     DNA for out.rbnf        using bits  2 to  3        142405  1.462  .9282
     DNA for out.rbnf        using bits  1 to  2        141956   .138  .5548

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::        
     ::     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 results for out.rbnf       
 Chi-square with 5^5-5^4=2500 d.of f. for sample size:2560000
                               chisquare  equiv normal  p-value
  Results fo COUNT-THE-1's in successive bytes:
 byte stream for out.rbnf         2477.62      -.317      .375805
 byte stream for out.rbnf         2486.82      -.186      .426054

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::        
     ::     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.                                     ::        
     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::        
 Chi-square with 5^5-5^4=2500 d.of f. for sample size: 256000
                      chisquare  equiv normal  p value
  Results for COUNT-THE-1's in specified bytes:
           bits  1 to  8  2514.21       .201      .579609
           bits  2 to  9  2477.10      -.324      .373004
           bits  3 to 10  2390.35     -1.551      .060488
           bits  4 to 11  2632.85      1.879      .969864
           bits  5 to 12  2502.15       .030      .512130
           bits  6 to 13  2465.87      -.483      .314665
           bits  7 to 14  2563.54       .899      .815566
           bits  8 to 15  2399.58     -1.420      .077781
           bits  9 to 16  2436.49      -.898      .184554
           bits 10 to 17  2476.93      -.326      .372091
           bits 11 to 18  2406.77     -1.318      .093683
           bits 12 to 19  2453.43      -.659      .255059
           bits 13 to 20  2459.31      -.575      .282492
           bits 14 to 21  2563.16       .893      .814147
           bits 15 to 22  2472.57      -.388      .349022
           bits 16 to 23  2451.43      -.687      .246069
           bits 17 to 24  2583.23      1.177      .880418
           bits 18 to 25  2580.68      1.141      .873074
           bits 19 to 26  2669.23      2.393      .991652
           bits 20 to 27  2635.39      1.915      .972233
           bits 21 to 28  2517.50       .248      .597745
           bits 22 to 29  2541.06       .581      .719286
           bits 23 to 30  2411.56     -1.251      .105521
           bits 24 to 31  2541.16       .582      .719725
           bits 25 to 32  2494.24      -.081      .467557

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::        
     ::               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 ten tests on file out.rbnf       
            Of 12,000 tries, the average no. of successes
                 should be 3523 with sigma=21.9
            Successes: 3542    z-score:   .868 p-value: .807188
            Successes: 3528    z-score:   .228 p-value: .590298
            Successes: 3537    z-score:   .639 p-value: .738676
            Successes: 3524    z-score:   .046 p-value: .518210
            Successes: 3503    z-score:  -.913 p-value: .180558
            Successes: 3545    z-score:  1.005 p-value: .842447
            Successes: 3558    z-score:  1.598 p-value: .944998
            Successes: 3548    z-score:  1.142 p-value: .873180
            Successes: 3494    z-score: -1.324 p-value: .092718
            Successes: 3522    z-score:  -.046 p-value: .481790
 
           square size   avg. no.  parked   sample sigma
             100.            3530.100       19.110
            KSTEST for the above 10: p=  .580735

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::        
     ::               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 random integers in the file out.rbnf       
     Sample no.    d^2     avg     equiv uni            
           5     .4921    .7419     .390142
          10     .7743    .8703     .540751
          15    1.7631   1.1093     .830005
          20     .0318   1.1145     .031436
          25     .9183   1.1718     .602660
          30    1.6388   1.1154     .807384
          35    2.4699   1.0878     .916449
          40     .2971   1.0239     .258165
          45    1.7783   1.0087     .832579
          50     .4027    .9697     .332836
          55     .6409    .9686     .474872
          60    3.1668    .9705     .958527
          65     .6613   1.0651     .485522
          70    2.3505   1.1091     .905799
          75     .8778   1.0832     .586125
          80     .9308   1.0799     .607603
          85    4.9796   1.1029     .993293
          90     .0864   1.0789     .083175
          95     .4361   1.0861     .354855
         100    2.2774   1.0628     .898614
     MINIMUM DISTANCE TEST for out.rbnf       
          Result of KS test on 20 transformed mindist^2's:
                                  p-value= .414914

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 

     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::        
     ::              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.rbnf       
 sample no:  1     r^3=   2.497     p-value= .07986
 sample no:  2     r^3=    .944     p-value= .03097
 sample no:  3     r^3=  11.507     p-value= .31858
 sample no:  4     r^3=  18.522     p-value= .46066
 sample no:  5     r^3=  53.385     p-value= .83128
 sample no:  6     r^3=  24.988     p-value= .56523
 sample no:  7     r^3=  33.582     p-value= .67353
 sample no:  8     r^3=  52.342     p-value= .82531
 sample no:  9     r^3=  10.060     p-value= .28490
 sample no: 10     r^3=  37.835     p-value= .71667
 sample no: 11     r^3=  26.345     p-value= .58446
 sample no: 12     r^3=  18.111     p-value= .45321
 sample no: 13     r^3=   2.604     p-value= .08313
 sample no: 14     r^3=  22.719     p-value= .53107
 sample no: 15     r^3=   6.510     p-value= .19508
 sample no: 16     r^3=    .177     p-value= .00590
 sample no: 17     r^3=  48.487     p-value= .80135
 sample no: 18     r^3=  55.243     p-value= .84141
 sample no: 19     r^3=   5.339     p-value= .16303
 sample no: 20     r^3=   4.291     p-value= .13328
  A KS test is applied to those 20 p-values.
---------------------------------------------------------
       3DSPHERES test for file out.rbnf             p-value= .619721
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::        
     ::      This is the SQEEZE 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.rbnf       
         Table of standardized frequency counts
     ( (obs-exp)/sqrt(exp) )^2
        for j taking values <=6,7,8,...,47,>=48:
     -.8      .1      .3    -1.7     -.9      .5
     -.2      .6      .8      .2      .4     -.5
     -.5     -.8    -1.2      .1      .0     2.9
     1.0      .0    -1.4      .6      .3      .0
    -1.1    -2.0     -.1      .5      .5    -1.1
      .5      .6     -.5      .3     -.6     -.5
    -1.2      .8     1.3     -.1      .1     1.0
     -.1
           Chi-square with 42 degrees of freedom: 33.573
              z-score=  -.919  p-value= .179804
______________________________________________________________

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::        
     ::             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. The  p-values from ten     ::        
     :: KSTESTs are given still another KSTEST.                       ::        
     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::        
                Test no.  1      p-value  .936638
                Test no.  2      p-value  .237101
                Test no.  3      p-value  .309156
                Test no.  4      p-value  .961163
                Test no.  5      p-value  .272522
                Test no.  6      p-value  .492101
                Test no.  7      p-value  .301595
                Test no.  8      p-value  .099303
                Test no.  9      p-value  .175066
                Test no. 10      p-value  .397994
   Results of the OSUM test for out.rbnf       
        KSTEST on the above 10 p-values:  .700504

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::        
     ::     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 ::        
     :: repeated.                                                     ::        
     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::        
           The RUNS test for file out.rbnf       
     Up and down runs in a sample of 10000
_________________________________________________ 
                 Run test for out.rbnf       :
       runs up; ks test for 10 p's: .764152
     runs down; ks test for 10 p's: .703425
                 Run test for out.rbnf       :
       runs up; ks test for 10 p's: .888762
     runs down; ks test for 10 p's: .920232

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

     :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::        
     :: This is the CRAPS TEST. It plays 200,000 games of craps, finds::        
     :: 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), with      ::        
     :: 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.rbnf       
  No. of wins:  Observed Expected
                                98671    98585.86
                  98671= No. of wins, z-score=  .381 pvalue= .64832
   Analysis of Throws-per-Game:
 Chisq=  18.54 for 20 degrees of freedom, p=  .44802
               Throws Observed Expected  Chisq     Sum
                  1    66264    66666.7   2.432    2.432
                  2    38046    37654.3   4.074    6.506
                  3    27057    26954.7    .388    6.894
                  4    19229    19313.5    .369    7.264
                  5    13897    13851.4    .150    7.414
                  6     9866     9943.5    .605    8.018
                  7     7123     7145.0    .068    8.086
                  8     5066     5139.1   1.039    9.125
                  9     3679     3699.9    .118    9.243
                 10     2710     2666.3    .716    9.959
                 11     1992     1923.3   2.452   12.411
                 12     1379     1388.7    .068   12.479
                 13      981     1003.7    .514   12.994
                 14      719      726.1    .070   13.064
                 15      544      525.8    .627   13.691
                 16      374      381.2    .134   13.825
                 17      294      276.5   1.102   14.928
                 18      222      200.8   2.232   17.159
                 19      154      146.0    .440   17.600
                 20      102      106.2    .167   17.767
                 21      302      287.1    .772   18.538
            SUMMARY  FOR out.rbnf       
                p-value for no. of wins: .648324
                p-value for throws/game: .448015

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

 Results of DIEHARD battery of tests sent to file out.txt        
Heres the raw binary number file I generated:
https://dl.dropboxusercontent.com/u/306 ... b_out.rbnf
The distribution of p<0.05 and p>0.95 was around what you would expect for those values, given the huge number of tests. you should start getting concerned if you see a p=0.000000 or a p=1.000000 when you test your RNGs. (For best results just output a stream of random *bytes* for this test, because if you do bytes in an integer, you end up with a bunch of extra 00s in your file.)
(shpOrder gPlayership 'barrelRoll)
(plySetGenome gPlayer (list 'hycrotan 'nonBinary))
Image

User avatar
pixelfck
Militia Captain
Militia Captain
Posts: 571
Joined: Tue Aug 11, 2009 8:47 pm
Location: Travelling around in Europe

Sat Oct 12, 2013 10:13 am

george moromisato wrote:What algorithm did you use to generate the charts? Did you just use a random number for x and y coordinates and plot it?
I used a little javascript file, it basically does the following:

Code: Select all

for (i = 0; i < sampleCount; i++) {
	x = i;
	y = seededRandom(i, 0, 100);
	while (x >= canvasWidth) {
		x -= canvasWidth;
	}
	canvas.draw(new Point(x, y));
}
(download as .zip)

Wolfy wrote:if you're using integers, watch out for overlaps
I thought about this... It occurred to me that in this case, integer overflow would not matter? The resulting value would just wrap around and create an equally valid random outcome? But please correct me if you think I'm wrong.

Also, I tried to get the output from my algorithm accepted by Diehard, but I couldn't get it to work (my hex representation of the integers where wrongly formatted). Could you maybe give it a spin through Diehard? It would be interesting to see how flawed it is.

Cheers
Pixelfck

Bonus image:
Image
the Transcendence (seededRandom ...) and (random ...) methods.
Image
Download the Black Market Expansion from Xelerus.de today!
My other mods at xelerus.de

Locked