### Basic Examples

Basic Examples

Generate a sequence of random integers and apply a run count-based test:

sequence=RandomReal[{0,1},1000];

In[]:=

Visualize the sequence:

ArrayPlotPartition[sequence,16],

In[]:=

Out[]=

[sequence,"TestStatistic"]

In[]:=

506

Out[]=

[sequence,"PValue"]

In[]:=

0.508984

Out[]=

### Scope

Scope

Attempt to reject a non-random sequence:

subsequence=RandomReal[{0,1},10];

In[]:=

sequence=Flatten[Table[subsequence,200]];

In[]:=

ArrayPlotPartition[Take[sequence,200],25],

In[]:=

Out[]=

[sequence,"TestStatistic"]

In[]:=

800

Out[]=

[sequence,"PValue"]

In[]:=

7.59891×10

-45

Out[]=

### Possible Issues

Possible Issues

This test is not very powerful and fails to reject non-random sequences that repeat over longer intervals on occasion; ideally, it should be used in conjunction with another test:

subsequence=RandomReal[{0,1},200];

In[]:=

sequence=Flatten[Table[subsequence,10]];

In[]:=

ArrayPlotPartition[Take[sequence,200],25],

In[]:=

Out[]=

[sequence,"TestStatistic"]

In[]:=

1020

Out[]=

[sequence,"PValue"]

In[]:=

0.124778

Out[]=

### Neat Examples

Neat Examples

Visualize the sampling distribution of the test statistic:

samp=

[#,"TestStatistic"]&/@RandomReal[{0,1},{1000,1000}];

In[]:=

Histogram[samp,{1},"PDF"]

In[]:=

Out[]=