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.
GCD.test(x, B = 32, KS = TRUE, CSQ = TRUE, AD = TRUE, JB = TRUE,
test.k = TRUE, test.g = TRUE, mu, sd, alpha = 0.05)
an \(N*2\) matrix of integers that includes random data. See details for further information.
the length of words (B-bit).
if TRUE
, Kolmogorov-Smirnov goodness-of-fit test is applied.
if TRUE
, Chi-Square goodness-of-fit test is applied.
if TRUE
, Anderson-Darling goodness-of-fit test is applied.
if TRUE
, Jarque-Bera goodness-of-fit test is applied.
if TRUE
, randomness test is applied over the number of required iterations of the GCD operation.
if TRUE
, randomness test is applied over the value of greatest common divisor.
the mean of theoretical normal distribution that the number of required iterations follows.
the standard deviation of theoretical normal distribution that the number of required iterations follows.
a predetermined value of significance level with the default value of 0.05.
a \(4 x 1\) vector of p-values. Elements of sig.value.k
include p-value of Kolmogorov-Smirnov and Chi-Square tests, respectively.
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.
returns 0 if H0 is rejected and 1 otherwise in Kolmogorov-Smirnov goodness-of-fit test conducted over the number of required iterations.
returns 0 if H0 is rejected and 1 otherwise in Chi-Square goodness-of-fit test conducted over the number of required iterations.
returns 0 if H0 is rejected and 1 otherwise in Jarque-Bera goodness-of-fit test conducted over the number of required iterations.
returns 0 if H0 is rejected and 1 otherwise in Anderson-Darling goodness-of-fit test conducted over the number of required iterations.
returns 0 if H0 is rejected and 1 otherwise in Kolmogorov-Smirnov goodness-of-fit test conducted over the value of greatest common divisor.
returns 0 if H0 is rejected and 1 otherwise in Chi-Square goodness-of-fit test conducted over the value of greatest common divisor.
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,...
Marsaglia, G., Tsang, W.W., Some Difficult-to-pass tests of randomness. Journal of Statistical Software (2002), 7(3).
See the function GCD
that provides detailed results for the greatest common divisor operation.
# NOT RUN {
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)
# }
Run the code above in your browser using DataLab