A Lagged Fibbonacci Generator (LFG or sometimes LFib) is an example of a pseudorandom number generator. This class of pseudorandom number generator is aimed at being an improvment of the 'standard' linear congruential generator. These are based on the generalization of the Fibbonacci sequence.

The Fibonacci sequence may be described by the recurrence relation:

\(S_n = S_{n-1}+S_{n-2}\)

Hence, the new term is the sum of the last two terms in the sequence This can be generalized by the sequence:

\(S_n \equiv S_{n-j} \ast S_{n-k} \space (\text{mod }m), 0 < j <k\)

In which case, the new term is some combination of any two previous terms. m is usually a power of 2 (m = 2M), often 232 or 264. The \(\ast\) operator denotes a general binary operation. This may be either addition, subtraction, multiplication, or the bitwise exclusive-or operator (XOR). In this package, the \(\ast\) operator denotes addition.The theory of this type of generator is rather complex, and it may not be sufficient simply to choose random values for j and k. These generators also tend to be very sensitive to initialisation.

lfg(n, j = 24L, k = 55L, bitsize = 32L, operation = "+")

Arguments

n

Number of random numbers to generate.

j

Lag parameter j (0 < j < k).

k

Lag parameter k (j < k).

bitsize

Bit size for modulo (m = 2^bitsize).

operation

Character representing the operation: '+', '-', '*', '^' (XOR).

Value

NumericVector of generated values.

Details

For more information, see the Wikipedia page.

Examples

plot(
lfg(10000,j=7083 ,k=19937, bitsize=32, operation = '^')
  )