Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Use a discrete cosine transform–based method to test the randomness of a sequence of random reals
ResourceFunction["SpectralRandomnessTest"][sequence] conducts a discrete cosine transform-based test to asses the randomness of either a sequence of 0s and 1s or reals between 0 and 1, returning the associated p-value. | |
ResourceFunction["SpectralRandomnessTest"][sequence,"property"] conducts a discrete cosine transform-based test and returns the associated property. |
"TestStatistic" | returns the test statistic |
"PValue" | returns the p-value associated with the test |
Generate a sequence of random integers:
In[1]:= |
Visualize the sequence:
In[2]:= |
Out[2]= |
Apply a discrete cosine transform-based test:
In[3]:= |
Out[3]= |
In[4]:= |
Out[4]= |
Generate a sequence of random integers:
In[5]:= |
Visualize the sequence:
In[6]:= |
Out[6]= |
Apply a discrete cosine transform-based test:
In[7]:= |
Out[7]= |
In[8]:= |
Out[8]= |
Generate a sequence of random integers:
In[9]:= |
In[10]:= |
Visualize the sequence:
In[11]:= |
Out[11]= |
Attempt to reject a non-random sequence:
In[12]:= |
Out[12]= |
In[13]:= |
Out[13]= |
Test to see if rule 30 is random according to the spectral test:
In[14]:= |
In[15]:= |
Out[15]= |
In[16]:= |
Out[16]= |
For non-random data, the Kolmogorov–Smirnov test, a part of the entire test, may return ties. Observing such ties is a strong indicator that the data is non-random:
In[17]:= |
In[18]:= |
In[19]:= |
Out[19]= |
In[20]:= |
Out[20]= |
In[21]:= |
Out[21]= |
Visualize the sampling distribution of the test statistic:
In[22]:= |
In[23]:= |
Out[23]= |
This work is licensed under a Creative Commons Attribution 4.0 International License