NIST Random Number Test Suite

An implementation of the NIST Random Number Test Suite, based on their definition 800-22, reversion 1a, (2010)

A detailled description can be found here: 

http://csrc.nist.gov/rng/

Implemented by Ilja Gerhardt in 2010, based on the code of Nick Galbreath which had quite some bugs, so let's retain his BSD-license on this file...

Copyright (c) 2010, Ilja Gerhardt
Copyright (c) 2005, Nick Galbreath

All rights reserved.Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met :
  
  Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
  
  Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
  
  Neither the name of the gerhardt.ch nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
  
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED.IN NO EVENT SHALL ILJA GERHARDT AND/OR NICK GALTBREATH BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

And, of course, this notebook is CASE (Control - A, Shift - Enter) capable.
(You can evaluate all cells from the beginning to the end sequentially)

TestList

This is the list of tests, as defined in the original PDF file. The list is to name the tests and also names the function names. It is possible to design a test, which runs all the tests, based on this list

testlist={
"MonobitFrequencyTest",
"BlockFrequencyTest",
"RunsTest",
"LongestRunsOnes10000",
"BinaryMatrixRankTest",
"SpectralTest",
"NonOverlappingTemplateMatching",
"OverlapingTemplateMatching",
"MaurersUniversalStatisticTest",
"LinearComplexityTest",
"SerialTest",
"ApproximateEntropyTest",
"CumulativeSumsTest",
"RandomExcursionsTest",
"RandomExcursionsVariantTest",
"CumulativeSumsTestReverse",
"LempelZivCompressionTest"};

Numbers to Test

These are the test numbers, which are generated to reach 1000000 digits, such that we are able to test the results agains the list in the NIST' s PDF file (Appendix B)

BinExp[num_,d_]:=Module[{n,L},
If[d>$MaxPrecision,$MaxPrecision=d];
n=N[num,d];
L=First[RealDigits[n,2]]];

aa=StringJoin[Map[ToString,Join[BinExp[Pi,302500]]]];
binpi=StringTake[aa,{1,(10^6)}];binpir=StringReverse[binpi];

aa=StringJoin[Map[ToString,Join[BinExp[E,302500]]]];
bine=StringTake[aa,{1,(10^6)}];biner=StringReverse[bine];

aa=StringJoin[Map[ToString,Join[BinExp[Sqrt[2],302500]]]];
bins2=StringTake[aa,{1,(10^6)}];bins2r=StringReverse[bins2];

aa=StringJoin[Map[ToString,Join[BinExp[Sqrt[3],302500]]]];
bins3=StringTake[aa,{1,(10^6)}];bins3r=StringReverse[bins3];

If you want to generate a Random BitStream, here you go :

length=100; (* please set the needed length of the bitstream *)

randomstring=StringJoin[Table[ToString[RandomInteger[1]],{length}]]

If you want to export the data in a format the native sts - Suite can read, here is the code for it

textout=Map["   "<>#&,StringPartition[binpi,25]]; (* the original NIST files contain 3 blanks in the beginning of each line *)

Export["/tmp/data.pi.txt",textout];

Reference Values, acquired with the C - variant of the tests

These Values can also be found in Appendix B of the Test - Description

Command in the ~/sts-2.1.1/experiments/AlgorithmTesting/ dir :

find./ -name "results.txt" - print - exec cat {}\; > sqrt3outcomes.txt
 
Then: pick out the results per hand ;(

pires={0.578211,0.380615,0.419268,0.024390,0.083553,0.010186,0.165757,0.296897,0.669012,0.255475,{0.143005,0.034354},0.361595,0.628308,{0.279235,0.639439,0.268428,0.613106,0.844143,0.794540,0.790685,0.627278},{0.995094,0.926985,0.854948,0.657527,0.760966,0.687364,0.864963,0.650024,0.760966,0.509815,0.714432,0.954795,0.708635,0.806410,0.945155,0.932760,0.911398,1.000000},0.663369,""};

eres={0.953749,0.211072,0.561917,0.718945,0.306156,0.847187,0.078790,0.110434,0.282568,0.826335,{0.766182,0.462921},0.700073,0.669886,{0.573306,0.197996,0.164011,0.007779,0.786868,0.440912,0.797854,0.778186},{0.858946,0.794755,0.576249,0.493417,0.633873,0.917283,0.934708,0.816012,0.826009,0.137861,0.200642,0.441254,0.939291,0.505683,0.445935,0.512207,0.538635,0.593930},0.724265,""};

s2res={0.811881,0.833222,0.313427,0.012117,0.823810,0.581909,0.569461,0.791982,0.130805,0.317127,{0.861925,0.629225},0.884740,0.879009,{0.650667,0.525084,0.462831,0.579449,0.216235,0.278867,0.649018,0.429218},{0.065590,0.069405,0.100090,0.176071,0.467959,0.986690,0.668892,0.772734,0.566118,0.059678,0.116087,0.330171,0.442857,0.412797,0.866139,0.503373,0.440628,0.397735},0.957206,""};

s3res={0.610051,0.473961,0.261123,0.446726,0.314498,0.776046,0.532235,0.082716,0.165981,0.346469,{0.157500,0.171100},0.180481,0.917121,{0.140338,0.464827,0.095758,0.372229,0.783283,0.380383,0.616285,0.586895
},{0.379094,0.574799,0.616585,0.721501,0.697462,0.269151,0.082536,0.112630,0.155066,0.798247,0.719052,0.375650,0.414970,0.733238,0.791062,0.797183,0.788604,0.756576},0.689519,""};

The Random Tests

2.0 Common Code

StringPartition[s_String, m_Integer] := 
If[m<100,
StringCases[s, Apply[StringExpression, Table[_, {m}]], Overlaps->False],
FromCharacterCode[Partition[ToCharacterCode[s], m]]]
StringPartition[s_String, m_Integer, 1] :=
StringCases[s, Apply[StringExpression, Table[_, {m}]], Overlaps->True]
BinaryString[x_Integer, n_Integer] :=StringJoin[Map[FromCharacterCode[#+48] &,IntegerDigits[x,2,n]]]
StringPartitionArray[s_String, m_Integer] := FromCharacterCode[Partition[ToCharacterCode[s], m]]
RandomBinaryString[m_Integer] := FromCharacterCode[Table[Random[Integer]+48, {m}]]
BinaryStringToDigits[s_String] := ToCharacterCode[s] - 48
BinaryStringToInteger[s_String] := FromDigits[ ToCharacterCode[s] - 48, 2]

2.1 Monobit Frequency Test

MonobitFrequencyTest[s_String] := Module[{n = StringLength[s]},
sn =Apply[Plus,(ToCharacterCode[s] - 48)*2-1];
sobs = Abs[sn] /(Sqrt[n]);
pval= Erfc[sobs /(Sqrt[2])];
pval]

2.2 Block Frequency Test

BlockFrequencyTest2[s_String, m_Integer] := Map[Count[#,1]&, Partition[(ToCharacterCode[s] - 48), m]]

BlockFrequencyTest[s_String, m_Integer:128] :=
 Module[{},
freq =Map[StringCount[#,"1"]&, StringPartition[s, m]]/ m;
n = Length[freq];
chisqr = 4*m*Apply[Plus, Map[(((# - 1/2))^2)&, freq]];
pval = GammaRegularized[ n/2, chisqr /2];
pval]

2.3 Runs Test

RunsTest[s_String] := 
Module[{},
n = StringLength[s];
pi = StringCount[s,"1"] / n;
vobs = StringCount[s,RegularExpression["0+|1+"]];
pval = Erfc[Abs[(vobs - 2  n  pi(1-pi))]/ (2(Sqrt[2n])pi(1-pi))];
pval];

2.4 Longest Runs Test

LongestRunOnes8[s_String] := 
Module[{m=8, k=3, pik = {0.2148, 0.3672, 0.2305, 0.1875}},
blocks = StringPartition[s, m];
n= Length[blocks];
counts = Map[ Max[1, Min[4,Max[StringLength[StringSplit[#, "0"]]]]]&, blocks];
freqs = Table[Count[counts, i], {i,1,4}];
chisqr = Apply[Plus,MapThread[ ((((#1 - n* #2))^2)) / (n * #2)&, {freqs, pik}]];
pval = GammaRegularized[k/2, chisqr / 2];
pval]

LongestRunsOnes128[s_String] :=
Module[{blocks,m=128, k=5, pik = {0.1174, 0.2430, 0.2493, 0.1752, 0.1027,0.1124}},
blocks = StringPartition[s, m];
n= Length[blocks];
counts = Map[ Max[4,Min[9,Max[StringLength[StringSplit[#,"0"]]]]]&, blocks];
freqs = Table[Count[counts, i], {i,4,9}];
chisqr = Apply[Plus,MapThread[ ((((#1 - n* #2))^2)) / (n * #2)&, {freqs, pik}]];
pval = GammaRegularized[k/2, chisqr / 2];
pval]

LongestRunsOnes10000[s_String] :=
Module[{},
m=(10^4);k=6;pik = {0.0882, 0.2092, 0.2483, 0.1933, 0.1208,0.0675, 0.0727};
 blocks=StringPartition[s,m];
n= Length[blocks];
counts=Map[Max[10,Min[16,Max[StringLength[StringSplit[#,"0"]]]]]&,blocks];
freqs=Table[Count[counts, i], {i,10,16}];
chisqr=Apply[Plus,MapThread[((((#1-n*#2))^2))/(n*#2)&, {freqs, pik}]];
pval=GammaRegularized[k/2, chisqr/2];
pval]

2.5 Binary Matrix Rank Test

BinaryMatrixRankTest[s_String, m_:32, q_:32] := Module[{},
p1=Product[1-(1/(2^j)),{j,1,30}];p2=2 p1;p3=1-p1-p2;
r =Map[MatrixRank[#,Modulus->2]&,Partition[Partition[(ToCharacterCode[s] - 48), m], q]];
n = Length[r];
fm = Count[r,m];
fm1 = Count[r,m-1];
chisqr = ((((fm-p1 n))^2)/(p1 n))+ ((((fm1-p2 n))^2)/(p2 n))+ ((((n-fm-fm1-p3 n))^2)/(p3 n));
pval =Exp[-chisqr/2];
pval];

2.6 Spectral Test

SpectralTest[str_String] := Module[{},
n = StringLength[str];
str2 = (ToCharacterCode[str] - 48)*2-1;
dst = Fourier[str2,FourierParameters->{1,-1}];
dstreal =Drop[Take[Abs[dst],IntegerPart[n/2]+1],1];
t=(Sqrt[Log[1/0.05] n]);
n0 = 0.95 n/2;
n1 = Length[Select[dstreal,#<t&]];
d= (n1 - n0) / (Sqrt[n 0.95 0.05 / 4]);
pval = Erfc[Abs[d]/(Sqrt[2])];
pval];

2.7 Non-overalpping Template Matching Test

NonOverlappingTemplateMatching[s_String, b_String:"000000001", NN_:8] :=
Module[{},
n= StringLength[s];
m=StringLength[b];
M=IntegerPart[n/NN];
blocks = StringPartition[s,M];
counts = Map[StringCount[#, b]&, blocks];
mu = (M-m+1)/((2^m));
sigmas = M((1/(2^m))- (((2m -1))/(2^((2m)))));
chisqr = Sum[(((counts[[i]]-mu))^2), {i,1, Length[counts]}] / sigmas;
pval = GammaRegularized[Length[blocks]/2, chisqr / 2];
pval];

2.8 Overlapping Template Matching Test

Pr[0, x_] := Power[E, -x]
Pr[u_Integer, x_] :=x*(E^-x)*(2^-u)* Sum[ Binomial[u-1, i - 1]*((x^((i-1))))/Factorial[i], {i, 1,u}];

OverlapingTemplateMatching[s_String, b_String:"111111111", M_:1032, K_:5] := 
Module[{}, 
n = StringLength[s];
bigN = Floor[n/M];
m = StringLength[b];
lambda = (M-m +1)*((2^(-m)));
eta = lambda / 2;
pi = Table[Pr[i, eta],{i, 0, K-1}];
AppendTo[pi, 1- Apply[Plus, pi]];
v = Table[0, {K+1}];
blocks = StringPartition[s,M];
blockLen = StringLength[blocks[[1]]];
counts = Map[Min[StringCount[#, b, Overlaps->True], K]&, blocks];
Scan[(v[[#+1]]++)&, counts];
chisqr = Sum[ ((((v[[i]]-bigN* pi[[i]] ))^2)/(bigN*pi[[i]])),  {i,1,K+1}];
pval = GammaRegularized[K/2, chisqr / 2];
pval];

2.9 Maurer's Universal Statistic Test

MaurersUniversalStatisticTest[s_String, L_Integer:7, q_Integer:1280] :=
Module[
{},
ru = {{0.7326495, 0.690}, {1.5374383, 1.338}, {2.4016068, 1.901}, {3.3112247, 2.358}, {4.2534266, 2.705}, {5.2177052, 2.954}, {6.1962507, 3.125}, {7.1836656, 3.238}, {8.1764248, 3.311}, {9.1723243, 3.356}, {10.170032, 3.384}, {11.168765, 3.401}, {12.168070, 3.410}, {13.167693, 3.416}, {14.167488, 3.419}, {15.167379, 3.421}};
blocks = Map[1 + FromDigits[#, 2]&, Partition[ToCharacterCode[s] - 48, L]];
k=Length[blocks]-q;
states=Table[0,{i,(2^L)}];
Do[ states[[ blocks[[i]] ]] = i , {i,1, q}];
sum= 0.0;
Do[sum+=Log[2,i-states[[blocks[[i]] ]]];
states[[blocks[[i]]]]=i;
, {i, q+1, Length[blocks]}];
fn = sum / k;
c=0.7-(0.8/L)+(4+(32/L))((k^(-3/L))/15);
sigma=c(Sqrt[((ru[[L,2]])/k)]);
pval = Erfc[((Abs[fn-ru[[L, 1]]])/((Sqrt[2 ]) sigma)) ];
pval]

2.10 Linear Complexity Test

LinearComplexity = Compile[{{u,_Integer,1}}, Module[{len,b,c,d,p,tmp,l,m},
len = Length[u]; l=0; m=0;
c=b=ReplacePart[Table[0,{len}], 1,1];
Do[
d= Mod[u[[n]] + Dot[ Take[c, {2, l+1}],Reverse[Take[u,{n-l , n-1 }]]], 2];
If[d==1,
tmp = c;
p = Table[0, {len}];
Do[If[b[[i]]==1,p[[i+n-m]] = 1], {i,1, l+1}];
c  = Mod[c+p, 2];
If[2*l≤n,l=n-l;m=n;b=tmp;];]
,{n, 1, len}];l]];

LinearComplexityTest[s_String, m_Integer:500] :=
Module[{},
k=6;
pi={0.01047, 0.03125, 0.125,0.5,0.25,0.0625, 0.020833};
avg=(m/2)+(9+-(1^(m+1)))/36 - (m/3+2/9)/(2^m);
blocks=StringPartition[s,m];
bigN=Length[blocks];
lc=Map[LinearComplexity[BinaryStringToDigits[#]]&, blocks];
t=Map[(Power[-1,m]*(#-avg) + 2/9)&, lc];
v=Reverse[Map[Length,BinLists[-1 t,{{-Infinity,-2.5, -1.5, -0.5, 0.5, 1.5, 2.5,Infinity}}]]];
chisqr=Sum[((((v[[i]]-bigN*pi[[i]]))^2)/((bigN * pi[[i]]))),{i,1,Length[v]}];
pval=GammaRegularized[k/2,chisqr/2];
pval];

2.11 Serial Test

SerialTest[s_String,m_Integer:16] :=
Module[{},
n = StringLength[s];
f1=Reverse[Sort[Tally[StringPartition[s<>StringTake[s,m-1],m,1]]],2];
f2=Reverse[Sort[Tally[StringPartition[s<>StringTake[s,m-2],m-1,1]]],2];
f3=Reverse[Sort[Tally[StringPartition[s<>StringTake[s,m-3],m-2,1]]],2];
psim1 = 0;
psim2 = 0;
psim3 = 0;
If[m ≥ 0,psim1 = Power[2,m]*Fold[Plus[#1, Power[Part[#2,1], 2]]&, 0, f1] /n -n];
If[m ≥ 1,
psim2 = Power[2,m-1]*Fold[Plus[#1, Power[Part[#2,1], 2]]&, 0, f2] /n -n];
If[m ≥ 2,
psim3 = Power[2,m-2]*Fold[Plus[#1, Power[Part[#2,1], 2]]&, 0, f3] /n -n];
d1 = psim1 - psim2;
d2 = psim1 - 2*psim2 + psim3;
pval = {GammaRegularized[(2^(m-2)),d1/2],  GammaRegularized[(2^(m-3)),d2/2]};
pval]

2.12 Approximate Entropy Test

ApproximateEntropyTest[s_String, m_Integer:10] :=
Module[{},
n = StringLength[s];
f1=Reverse[Sort[Tally[StringPartition[s<>StringTake[s,m-1],m,1]]],2];
f2=Reverse[Sort[Tally[StringPartition[s<>StringTake[s,m],m+1,1]]],2];
c1 = Map[#[[1]]&, f1] / n;
c2 = Map[#[[1]]&, f2] / n;
phi1 = Apply[Plus, Map[# Log[#]&, c1]];
phi2 = Apply[Plus, Map[# Log[#]&, c2]];
apen = phi1 - phi2;
chisqr = 2n(Log[2] -apen);
pval =GammaRegularized[(2^((m-1))),chisqr/2];
pval]

2.13 Cumulative Sums Test

CumulativeSumsTest[s_String] := Module[ {},
n=StringLength[s];
 ndist=NormalDistribution[0,1];
cs=Accumulate[ (ToCharacterCode[s] - 48)*2-1];
z=Max[Abs[cs]];
pval= 1-Apply[Plus, Table[CDF[ndist, (4k+1)z/(Sqrt[n])]- CDF[ndist, (4k-1)z/(Sqrt[n])], {k, Floor[(-Floor[n/z] + 1)/4], Floor[(Floor[n/z] -1)/4]}]] + Apply[Plus,Table[CDF[ndist,(4k+3)z/(Sqrt[n])] - CDF[ndist, (4k+1)z/(Sqrt[n])], {k, Floor[(-Floor[n/z] -3)/4], Floor[(Floor[n/z] -1)/4]}]];
pval]

2.14 Random Excursions Test

freqCycles[cycles_List, x_Integer] := Module[{},
 tmp = Map[Min[{5, Count[#, x]}]&, cycles];
 Table[Count[tmp, i], {i,0,5}]
];

Remove[pik];
pik[0, x_] := 1 - 1/(2*Abs[x]);
pik[k_, x_] := (1/(4*x*x))(1-1/(2*Abs[x]))^(k-1);
pik[5, x_] := (1/(2*Abs[x]))(1-1/(2*Abs[x]))^4;
xvals = {-4,-3,-2,-1,1,2,3,4};
pikTable = Map[Table[ pik[i, #], {i,0,5}]& , xvals];

achisqr[x_, y_, j_] := Apply[Plus,MapThread[ ((((#1 - j*#2))^2))/(j * #2)&, {x, y}]];

RandomExcursionsTest[str_String] :=
Module[{}, 
cumsum = Flatten[{0,Accumulate[(ToCharacterCode[str] - 48)*2-1 ], 0}];
cyclePositions = Partition[Flatten[Position[cumsum, 0]], 2, 1];
cycles = Map[Take[cumsum, #]&, cyclePositions];
j = Length[cycles];
stateCyclesTable = Map[freqCycles[cycles,#]&, xvals];
chisqr =MapThread[achisqr[#1, #2, j]&, {stateCyclesTable, pikTable}];
pval = Map[GammaRegularized[5/2,#/2]&, chisqr];
pval = Table[{xvals[[ii]],GammaRegularized[5/2,chisqr[[ii]]/2]}, {ii,1,Length[chisqr]}];
pval];

2.15 Random Excusions Variant Test

getFreq[f_List, x_] := Module[{},
result = Select[f, #[[2]] == x &];
If[Length[result]==0, 0, result[[1,1]]]];

RandomExcursionsVariantTest[s_String] :=
Module[{},
 cumsum = Accumulate[(ToCharacterCode[s] - 48)*2-1 ];
freq = Select[Reverse[Sort[Tally[cumsum]],2], Abs[#[[2]] ] ≤ 9 &];
j = getFreq[freq, 0]+1;
pval =Map[ {#,Erfc[Abs[getFreq[freq,#] - j]/Sqrt[2 *j*(4*Abs[#] - 2)]]}&, {-9,-8,-7,-6,-5,-4,-3,-2,-1,1,2,3,4,5,6,7,8,9}];
pval];

2.16 Cumulative Sums Test Reverse

CumulativeSumsTestReverse[s_String] := CumulativeSumsTest[StringReverse[s]];

2.17 Lempel-Ziv Compression Test

LempelZivCompressionTest[s_String] :=
Module[{minj = 0,i = 1, j = 0, n = StringLength[s], tmp, μ = 69586.25, sigma = 70.448718, words, wordlen},
s2 = BinaryStringToDigits[s];
wobs = 0;
While[ i +j  ≤ n,
tmp =  s2[[Range[i,i+j] ]];
If[Head[words[tmp]] =!= words, j++; Continue[]];
words[tmp] = tmp;
 ++wobs;
i += j+1;
If[Head[wordlen[j]] === wordlen,wordlen[j] =Power[2, j+1]-1, --wordlen[j]];
If[wordlen[minj] == 0, ++minj];
 j = minj
];
pval = Erfc[(μ - wobs )/Sqrt[2*sigma]] /2;
pval];

Trial of the code

Test

Let' s compare the outcomes here to the published outcomes on the pages B - 1 to B - 3 in the NIST publication

The values, which are listed in the file are copied by hand from the test results from the sts implementation in C

num=Length[testlist];

Dynamic[tst] (* for the impatient to see which test is running *)

Test (10^6)digits of π

outlist1={{"Number","Name","P-Value","Reference Value","Time"}};
Do[
{tim,out}=Timing[ToExpression[testlist[[tst]]<>"[binpi]"]//N];
AppendTo[outlist1,{tst,testlist[[tst]],out,pires[[tst]],tim}];
,{tst,1,num}]

Grid[outlist1,Frame->All,Background->{None,{Green}}]

Test (10^6) digits of E

outlist2={{"Number","Name","P-Value","Reference Value","Time"}};
Do[
{tim,out}=Timing[ToExpression[testlist[[tst]]<>"[bine]"]//N];
AppendTo[outlist2,{tst,testlist[[tst]],out,eres[[tst]],tim}];
,{tst,1,num}]

Grid[outlist2,Frame->All,Background->{None,{Green}}]

Test (10^6) digits of(Sqrt[2])

outlist3={{"Number","Name","P-Value","Reference Value","Time"}};
Do[
{tim,out}=Timing[ToExpression[testlist[[tst]]<>"[bins2]"]//N];
AppendTo[outlist3,{tst,testlist[[tst]],out,s2res[[tst]],tim}];
,{tst,1,num}]

Grid[outlist3,Frame->All,Background->{None,{Green}}]

Test (10^6) digits of (Sqrt[3])

outlist4={{"Number","Name","P-Value","Reference Value","Time"}};
Do[
{tim,out}=Timing[ToExpression[testlist[[tst]]<>"[bins3]"]//N];
AppendTo[outlist4,{tst,testlist[[tst]],out,s3res[[tst]],tim}];
,{tst,1,num}]

Grid[outlist4,Frame->All,Background->{None,{Green}}]

Test only one test (given a number)

tst=2;
outlist5={{"Number","TestBins","Name of Test","P-Value"}};
AppendTo[outlist5,{tst,"π",testlist[[tst]],ToExpression[testlist[[tst]]<>"[binpi]"]//N}];
AppendTo[outlist5,{tst,"E",testlist[[tst]],ToExpression[testlist[[tst]]<>"[bine]"]//N}];
AppendTo[outlist5,{tst,"(Sqrt[2])",testlist[[tst]],ToExpression[testlist[[tst]]<>"[bins2]"]//N}];
AppendTo[outlist5,{tst,"(Sqrt[3])",testlist[[tst]],ToExpression[testlist[[tst]]<>"[bins3]"]//N}];

Grid[outlist5,Frame->All,Background->{None,{Green}}]

Graphics

Display Randomness

randompart=ToExpression[StringPartition[StringTake[binpi,640*480],1]];

gg=Partition[randompart,640];

aa=Graphics[Raster[gg],ImageSize-> 642,Background-> White,PlotRangePadding->None]

Show results of the Random Number Tests

vv=outlist1;name="π";

vals=Table[
If[
Length[vv[[xx,3]]]>0,
Switch[xx,12,vv[[xx,3,1]],15,vv[[xx,3,5,2]],16,vv[[xx,3,9,2]]]
,vv[[xx,3]]]
,{xx,2,Length[vv]}];

plotvals=Log[10,1000vals];

yticks=Table[{xx,N[(10^(xx-3))]},{xx,0,3,1}];

xticks=Table[{xx,""},{xx,0,Length[vals]}];

chart=BarChart[
plotvals,
BarSpacing->0,
PlotRange-> {{0,Length[vals]},{0.01,Log[10,1000]}},
FrameTicks->{xticks,yticks},FrameStyle-> Thick,ChartStyle-> Thick,
LabelingFunction->(ToString[0.001((10^(#1)))]&),
ChartElementFunction->"FadingRectangle",ChartBaseStyle->EdgeForm[{Thin,Darker[Darker[Blue]]}],
Frame-> True,PlotLabel-> Style["NIST Random Number Test Suite for \!\(\*SuperscriptBox[\(10\), \(\(6\)\(\\ \)\)]\)digits of "<>name,FontSize-> 20],
BaseStyle-> {FontFamily-> "Arial",FontSize-> 10},
FrameTicksStyle->Directive[16],
FrameLabel->{Style["Random Number Test",FontSize-> 16],Style["p-Value",FontSize-> 16]},
ChartLabels->Placed[testlist,Bottom,Rotate[#,Pi/2]&],
ImageSize-> 600,Epilog-> {Red,Line[{{0,1},{Length[vals],1}}],Text[Style["Significance Level",FontSize-> 16],{3.5,1},Background-> RGBColor[1,1,1,0.8]]}]