# Function Repository Resource:

# SpectralRandomnessTest

Use a discrete cosine transform–based method to test the randomness of a sequence of random reals

Contributed by: Emmy/Noah Blumenthal
noahb320@gmail.com
emmyb320@bu.edu
 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. ResourceFunction["SpectralRandomnessTest"][sequence,"property"] conducts a discrete cosine transform-based test and returns the associated property.

## Details and Options

Properties include:
 "TestStatistic" returns the test statistic "PValue" returns the p-value associated with the test
The test statistic is generated by comparing the discrete cosine transformed data with the normal distribution using the Kolmogorov-Smirnov test.
The test works for sequences of of random reals between 0 and 1 and sequences of only 0s and 1s

## Examples

### Basic Examples

Generate a sequence of random reals and apply a discrete cosine transform-based test:

 In:= Visualize the sequence:

 In:= Out= In:= Out= In:= Out= Generate a sequence of random integers and apply a discrete cosine transform-based test:

 In:= Visualize the sequence:

 In:= Out= In:= Out= In:= Out= ### Scope

Attempt to reject a non-random sequence:

 In:= In:= In:= Out= In:=  Out= In:=  Out= ### Applications

Test to see if rule 30 is random according to the spectral test:

 In:= In:= Out= In:= Out= ### Possible Issues

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:= In:= In:= Out= In:=  Out= In:=  Out= ### Neat Examples

Visualize the sampling distribution of the test statistic:

 In:= In:= Out= 