# birthday.spacings: Birthday Spacings Test In CryptRndTest: Statistical Tests for Cryptographic Randomness

 birthday.spacings R Documentation

## Birthday Spacings Test

### Description

Performs Birthday Spacings test of Marsaglia and Tsang (2002) to evaluate the randomness of an RNG. The Kolmogorov-Smirnov, Anderson-Darling, and Chi-Square tests are applied as goodness-of-fit tests.

### Usage

```birthday.spacings(x, m = 128, n = 2^16, alpha = 0.05, lambda, num.class = 10)
```

### Arguments

 `x` a vector that includes random integers. `m` the number of birthdays. `n` the length of year. `alpha` a predetermined value of significance level with the default value of 0.05. `lambda` mean of Poisson distribution that constitutes theoretical cumulative distribution function in goodness-of-fit tests. See Details section. `num.class` number of classes in the constructed frequency table for goodness-of-fit testing.

### Details

This is one of the "difficult to pass tests" that RNG's that are able to pass this set of tests possibly pass most of the tests included in the Diehard Battery of Tests.

To conduct the test, m birthdays are randomly chosen from a year composed of n days. When the birthdays are sorted, asymptotic distribution of the number of duplicated values among the spacings between birthdays is Poisson with mean λ=m^3/(4n). For most of the cases, this formula for `lambda` is useful. However, user should check suitability of the value entered for `lambda`. Note that some suitable values for m and n are given by Marsaglia and Tsang (2002).

The argument `num.class` should be increased along with increasing bit-length. It can be set to 5 for testing with 8-bit and to 10 for testing with 16-bit and higher.

### Value

 `AD.statistic` calculated value of the test statistic of Anderson-Darling goodness-of-fit test. `AD.pvalue` p-value of the test of Anderson-Darling goodness-of-fit test. `AD.result` returns 0 if H0 is rejected and 1 otherwise in Anderson-Darling goodness-of-fit test. `KS.statistic` calculated value of the test statistic of Kolmogorov-Smirnov goodness-of-fit test. `KS.pvalue` p-value of the test of Kolmogorov-Smirnov goodness-of-fit test. `KS.result` returns 0 if H0 is rejected and 1 otherwise in Kolmogorov-Smirnov goodness-of-fit test. `CS.statistic` calculated value of the test statistic of Chi-Square goodness-of-fit test. `CS.pvalue` p-value of the test of Chi-Square goodness-of-fit test. `CS.result` returns 0 if H0 is rejected and 1 otherwise in Chi-Square goodness-of-fit test.

### Author(s)

Haydar Demirhan

Maintainer: Haydar Demirhan <haydarde@hacettepe.edu.tr>

### References

Marsaglia, G., Tsang, W.W., Some Difficult-to-pass tests of randomness. Journal of Statistical Software (2002), 7(3).

### Examples

```
RNGkind(kind = "L'Ecuyer-CMRG")
B=16                  # Bit length is 16.
m=32                  # Number of birthdays is 64.
n=2^B                 # Length of year is 65536.
lambda=(m^3)/(4*n)
k=5000                # Generate 5000 integers.
x=round(runif(k,0,(2^B-1)))
alpha = 0.05
test=birthday.spacings(x, m, n, alpha, lambda, num.class=10)
print(test)

```

CryptRndTest documentation built on April 22, 2022, 9:07 a.m.