Wolfram Function Repository
Instantuse addon 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 transformbased test to asses the randomness of either a sequence of 0s and 1s or reals between 0 and 1. 

ResourceFunction["SpectralRandomnessTest"][sequence,"property"] conducts a discrete cosine transformbased test and returns the associated property. 
Generate a sequence of random reals and apply a discrete cosine transformbased test:
In[1]:= 

Visualize the sequence:
In[2]:= 

Out[2]= 

In[3]:= 

Out[3]= 

In[4]:= 

Out[4]= 

Generate a sequence of random integers and apply a discrete cosine transformbased test:
In[5]:= 

Visualize the sequence:
In[6]:= 

Out[6]= 

In[7]:= 

Out[7]= 

In[8]:= 

Out[8]= 

Attempt to reject a nonrandom sequence:
In[9]:= 

In[10]:= 

In[11]:= 

Out[11]= 

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 nonrandom 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