mCracker: Modulus Cracker

View source: R/mCracker.R

mCrackerR Documentation

Modulus Cracker

Description

Infers the modulus m for a congruential random number generator.

Usage

mCracker(U, par = 1e6, maxit = 100) 

Arguments

U

a numeric vector consisting of n (say 10000) uniform(0,1) pseudorandom numbers of the form x1/m, x2/m, ..., xn/m.

par

an integer guess as to an upper bound on the smallest integer in the sequence x1, x2, ..., xn.

maxit

maximum number of iterations allowed.

Details

Basic idea: Let x(1) denote the minimum order statistic in x1, x2, ..., xn. Then the set (x1/m)/(x(1)/m)*(1:par) must contain at least one integer, and m is in that set, if par has been set correctly.

Value

a list consisting of

m

the integer value of m

firstInteger

the minimum order statistic of the set x1, x2, ..., xm

Examples

# set.seed(33663)
x <- runif(1000000)
Y <- mCracker(x)$m
log(Y, 2)  # should be 32

MiscMath documentation built on April 13, 2025, 9:07 a.m.