A Lagged Fibonacci generator (LFG or sometimes LFib) is an example of a pseudorandom number generator. This class of random number generator is aimed at being an improvement on the 'standard' linear congruential generator. These are based on a generalisation of the Fibonacci sequence.
The Fibonacci sequence may be described by the recurrence relation:
Sn=Sn-1+Sn-2
Hence, the new term is the sum of the last two terms in the sequence. This can be generalised to the sequence:
Sn\equivSn-j\starSn-k\pmod{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
\star
Generators of this type employ k words of state (they 'remember' the last k values).
If the operation used is addition, then the generator is described as an Additive Lagged Fibonacci Generator or ALFG, if multiplication is used, it is a Multiplicative Lagged Fibonacci Generator or MLFG, and if the XOR operation is used, it is called a Two-tap generalised feedback shift register or GFSR. The Mersenne Twister algorithm is a variation on a GFSR. The GFSR is also related to the linear-feedback shift register, or LFSR.
The maximum period of lagged Fibonacci generators depends on the binary operation
\star
For the generator to achieve this maximum period, the polynomial:
y = xk + xj + 1
must be primitive over the integers mod 2. Values of j and k satisfying this constraint have been published in the literature.
j | 7 | 5 | 24 | 65 | 128 | 6 | 31 | 97 | 353 | 168 | 334 | 273 | 418 |
k | 10 | 17 | 55 | 71 | 159 | 31 | 63 | 127 | 521 | 521 | 607 | 607 | 1279 |
Another list of possible values for j and k is on page 29 of volume 2 of The Art of Computer Programming:
(24, 55), (38, 89), (37, 100), (30, 127), (83, 258), (107, 378), (273, 607), (1029, 2281), (576, 3217), (4187, 9689), (7083, 19937), (9739, 23209)
Note that the smaller number have short periods (only a few "random" numbers are generated before the first "random" number is repeated and the sequence restarts).
If addition is used, it is required that at least one of the first k values chosen to initialise the generator be odd. If multiplication is used, instead, it is required that all the first k values be odd, and further that at least one of them is ±3 mod 8.[3]
It has been suggested that good ratios between and are approximately the golden ratio.[4]
In a paper on four-tap shift registers, Robert M. Ziff, referring to LFGs that use the XOR operator, states that "It is now widely known that such generators, in particular with the two-tap rules such as R(103, 250), have serious deficiencies. Marsaglia observed very poor behavior with R(24, 55) and smaller generators, and advised against using generators of this type altogether. ... The basic problem of two-tap generators R(a, b) is that they have a built-in three-point correlation between
xn
xn-a
xn-b
p=max(a,b,c,\ldots)
Wikipedia page 'List of random number generators' lists other PRNGs including some with better statistical qualitites:
Toward a universal random number generator, G.Marsaglia, A.Zaman