The maximum period of lagged Fibonacci generators depends on the binary operation ⋆ {\displaystyle \star } . If addition or subtraction is used, the maximum period is (2k − 1) × 2M−1. If multiplication is used, the maximum period is (2k − 1) × 2M−3, or 1/4 of period of the additive case. If bitwise xor is used, the maximum period is 2k − 1.
For the generator to achieve this maximum period, the polynomial:
must be primitive over the integers mod 2. Values of j and k satisfying this constraint have been published in the literature.
Another list of possible values for j and k is on page 29 of volume 2 of The Art of Computer Programming:
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 j and k 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 x n {\displaystyle x_{n}} , x n − a {\displaystyle x_{n-a}} , and x n − b {\displaystyle x_{n-b}} , simply given by the generator itself ... While these correlations are spread over the size p = m a x ( a , b , c , … ) {\displaystyle p=max(a,b,c,\ldots )} of the generator itself, they can evidently still lead to significant errors.".5 This only refers to the standard LFG where each new number in the sequence depends on two previous numbers. A three-tap LFG has been shown to eliminate some statistical problems such as failing the Birthday Spacings and Generalized Triple tests.6
A simple implementation in the C programming language may look as shown below. This implementation uses 64-bit words and has a period of (2607 -1) × 263
Wikipedia page 'List of random number generators' lists other PRNGs including some with better statistical qualitites:
"RN Chapter". www.ccs.uky.edu. Archived from the original on 9 March 2004. Retrieved 13 January 2022. https://web.archive.org/web/20040309175607/http://www.ccs.uky.edu/csep/RN/RN.html ↩
"SPRNG: Scalable Parallel Pseudo-Random Number Generator Library". Archived from the original on 2010-06-14. Retrieved 2005-04-11. https://web.archive.org/web/20100614213822/http://www.nersc.gov/nusers/resources/software/libs/math/random/www2.0/DOCS/www/parameters.html ↩
Parameterizing Parallel Multiplicative Lagged-Fibonacci Generators, M. Mascagni, A. Srinivasan http://www.cs.fsu.edu/~asriniva/papers/mlfg.ps ↩
"Uniform random number generators for supercomputers", Richard Brent, 1992 https://openresearch-repository.anu.edu.au/bitstream/1885/40805/3/TR-CS-92-02.pdf ↩
"Four-tap shift-register-sequence random-number generators", Robert M. Ziff, Computers in Physics, 12(4), Jul/Aug 1998, pp. 385–392 https://arxiv.org/abs/cond-mat/9710104 ↩