Implements the Additive Congruential Random Number (ACORN) generator, a high-quality pseudorandom number generator based on additive lagged Fibonacci sequences. The generator uses the recurrence relation: Y[i] = (Y[i-1] + Y[i-2] + ... + Y[i-k-1]) mod M

acorn(seed, n, k = 1L, M = 1073741824L)

Arguments

seed

Initial seed value for the generator. Must satisfy 0 < seed < M. All internal states are initialized to this seed value.

n

Number of random values to generate. Must be non-negative.

k

Order of the generator (default = 1). Higher orders generally provide better statistical properties. The original ACORN algorithm recommends k = 10 for production use. Must be >= 1.

M

Modulus for the generator (default = 2^30 = 1073741824). Must be a power of two for efficient computation. The default provides approximately 30 bits of precision.

Value

A numeric vector of length n containing pseudo-random uniform values in the interval [0, 1).

Details

The ACORN generator maintains a state vector of k+1 previous values and generates new values by summing all previous values modulo M. This additive structure provides good statistical properties and a long period.

Key properties:

  • Period length increases with order k

  • k = 10 is recommended for general use (balances quality and speed)

  • M must be a power of 2 for efficient modulo operations

  • All generated values are in [0, 1) with resolution 1/M

Performance

Computational cost increases linearly with k. For k = 1, the generator is very fast but has limited statistical quality. For k = 10, it provides excellent quality at moderate computational cost.

References

Wikramaratna, R. S. (1989). ACORN - A new method for generating sequences of uniformly distributed pseudo-random numbers. Journal of Computational Physics, 83(1), 16-31.

Examples

if (FALSE) { # \dontrun{
# Generate 1000 random numbers with default settings (k=1)
rng1 <- acorn(seed = 12345, n = 1000)

# Use recommended order k=10 for better quality
rng10 <- acorn(seed = 12345, n = 1000, k = 10)

# Custom modulus (must be power of 2)
rng_custom <- acorn(seed = 54321, n = 500, k = 5, M = 2^20)

# Verify uniform distribution
hist(rng10, breaks = 50, main = "ACORN k=10")
} # }