Function Repository Resource:

ArcsineLawRandomnessTest

Source Notebook

Use the arcsine law to assess the randomness of a sequence of zeros and ones

Contributed by: Emmy/Noah Blumenthal
noahb320@gmail.com
emmyb320@bu.edu

ResourceFunction["ArcsineLawRandomnessTest"][sequence]

uses the arcsine law to test sequence for randomness and returns an associated p-value.

ResourceFunction["ArcsineLawRandomnessTest"][sequence,"property"]

tests sequence for randomness and returns the specified property.

Details and Options

Properties include:
"TestStatistic"returns the test statistic
"PValue"returns the p-value associated with the test
The test works only for sequences of zeros and ones.
ResourceFunction["ArcsineLawRandomnessTest"] results are generally invalid for sequence lengths shorter than 100.
The test returns a two-tailed p-value.

Examples

Basic Examples (3) 

Generate a sequence of random integers:

In[1]:=
SeedRandom[1];
sequence = RandomInteger[{0, 1}, 1000];

Visualize the sequence:

In[2]:=
ArrayPlot[Partition[sequence, 16]\[Transpose], Sequence[
 ImageSize -> Large, ColorFunction -> "CandyColors"]]
Out[2]=

Apply a runs-based test:

In[3]:=
ResourceFunction[
 "ArcsineLawRandomnessTest"][sequence, "TestStatistic"]
Out[3]=
In[4]:=
N@ResourceFunction["ArcsineLawRandomnessTest"][sequence, "PValue"]
Out[4]=

Applications (2) 

Generate a sequence of random integers:

In[5]:=
SeedRandom[2];
subsequence = RandomInteger[{0, 1}, 100];

Visualize the sequence:

In[6]:=
sequence = Flatten@Table[subsequence, 10];
In[7]:=
ArrayPlot[Partition[sequence, 16]\[Transpose], Sequence[
 ImageSize -> Large, ColorFunction -> "CandyColors"]]
Out[7]=

Attempt to reject a non-random sequence:

In[8]:=
ResourceFunction[
 "ArcsineLawRandomnessTest"][sequence, "TestStatistic"]
Out[8]=
In[9]:=
N@ResourceFunction["ArcsineLawRandomnessTest"][sequence, "PValue"]
Out[9]=

Test the randomness of rule 30:

In[10]:=
rule30seq = CellularAutomaton[30, {{1}, 0}, {100000, 0}]\[Transpose][[1]];
In[11]:=
ArrayPlot[Partition[Take[rule30seq, 1000], 16]\[Transpose], Sequence[
 ColorFunction -> "CandyColors", ImageSize -> Large]]
Out[11]=
In[12]:=
N@ResourceFunction["ArcsineLawRandomnessTest"][rule30seq]
Out[12]=

Possible Issues (1) 

ArcsineLawRandomnessTest requires sequences of length 100 or more:

In[13]:=
ResourceFunction["ArcsineLawRandomnessTest"][
 RandomInteger[{0, 1}, 50]]

Neat Examples (1) 

Visualize the sampling distribution of the test statistic:

In[14]:=
SeedRandom[1]
samp = Table[
   ResourceFunction["ArcsineLawRandomnessTest"][
    RandomInteger[{0, 1}, 1000], "TestStatistic"], 1000];
In[15]:=
Show[Histogram[samp, 50, "CDF"], Plot[2/\[Pi] ArcSin[Sqrt[x]], {x, 0, 1}]]
Out[15]=

Publisher

Emmy Blumenthal

Version History

  • 1.0.0 – 10 July 2019

Source Metadata

Related Resources

Author Notes

This test is entirely derived from the associated publication.

License Information