GCD.test: GCD Test

View source: R/GCD.test.R

GCD.testR Documentation

GCD Test

Description

Performs Greatest Common Divisor (GCD) test of Marsaglia and Tsang (2002) to evaluate the randomness of an RNG. Randomness tests are conducted over two outputs of greatest common divisor operation, namely the number of required iterations and the value of greatest common divisor. The Kolmogorov-Smirnov, Anderson-Darling, Jarque-Bera, and Chi-Square tests are applied as goodness-of-fit tests when the test is conducted over the number of required iterations. The Kolmogorov-Smirnov and Chi-Square tests are applied as goodness-of-fit tests when the test is conducted over the value of greatest common divisor.

Usage

GCD.test(x, B = 32, KS = TRUE, CSQ = TRUE, AD = TRUE, JB = TRUE, 
         test.k = TRUE, test.g = TRUE, mu, sd, alpha = 0.05)

Arguments

x

an N*2 matrix of integers that includes random data. See details for further information.

B

the length of words (B-bit).

KS

if TRUE, Kolmogorov-Smirnov goodness-of-fit test is applied.

CSQ

if TRUE, Chi-Square goodness-of-fit test is applied.

AD

if TRUE, Anderson-Darling goodness-of-fit test is applied.

JB

if TRUE, Jarque-Bera goodness-of-fit test is applied.

test.k

if TRUE, randomness test is applied over the number of required iterations of the GCD operation.

test.g

if TRUE, randomness test is applied over the value of greatest common divisor.

mu

the mean of theoretical normal distribution that the number of required iterations follows.

sd

the standard deviation of theoretical normal distribution that the number of required iterations follows.

alpha

a predetermined value of significance level with the default value of 0.05.

Details

Total number of integers to be tested is divided into two sets and entered as x. The GCD operation is applied to each row of x.

The number of required iterations follows a normal distribution with parameters mu and sd. Values of mu and sd are obtained by Monte Carlo simulation and given by Marsaglia and Tsang (2002) for 32-bit setting. We obtained values of mu and sd for other bit settings as mu=4.2503, sd=1.650673 for 8-bits, mu=8.8772, sd=2.38282 for 16-bits, ...for 24-bits,...

Value

sig.value.k

a 4 x 1 vector of p-values. Elements of sig.value.k include p-value of Kolmogorov-Smirnov and Chi-Square tests, respectively.

sig.value.g

a 2 x 1 vector of p-values. Elements of sig.value.g include p-value of Kolmogorov-Smirnov, Chi-Square, Jarque-Bera, and Anderson-Darling tests, respectively.

KS.result.k

returns 0 if H0 is rejected and 1 otherwise in Kolmogorov-Smirnov goodness-of-fit test conducted over the number of required iterations.

CSQ.result.k

returns 0 if H0 is rejected and 1 otherwise in Chi-Square goodness-of-fit test conducted over the number of required iterations.

JB.result.k

returns 0 if H0 is rejected and 1 otherwise in Jarque-Bera goodness-of-fit test conducted over the number of required iterations.

AD.result.k

returns 0 if H0 is rejected and 1 otherwise in Anderson-Darling goodness-of-fit test conducted over the number of required iterations.

KS.result.g

returns 0 if H0 is rejected and 1 otherwise in Kolmogorov-Smirnov goodness-of-fit test conducted over the value of greatest common divisor.

CSQ.result.g

returns 0 if H0 is rejected and 1 otherwise in Chi-Square goodness-of-fit test conducted over the value of greatest common divisor.

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).

See Also

See the function GCD that provides detailed results for the greatest common divisor operation.

Examples


RNGkind(kind = "L'Ecuyer-CMRG")
B=16                 # Bit length is 16. 
k=250                # Generate 250 integers.
x=array(0,dim=c(k,2))
x[,1]=round(runif(k,0,(2^B-1)))
x[,2]=round(runif(k,0,(2^B-1)))
mu=8.8772
sd=2.38282
alpha = 0.05
test=GCD.test(x,B=B,KS=TRUE,CSQ=TRUE,AD=TRUE,JB=TRUE,
              test.k=TRUE,test.g=TRUE,mu=mu,sd=sd,alpha=alpha)
print(test)


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