A Lagged Fibonacci generator (LFG or sometimes LFib) is an example of a
pseudorandom number generator
A pseudorandom number generator (PRNG), also known as a deterministic random bit generator (DRBG), is an algorithm for generating a sequence of numbers whose properties approximate the properties of sequences of random numbers. The PRNG-generate ...
. This class of
random number generator
Random number generation is a process by which, often by means of a random number generator (RNG), a sequence of numbers or symbols that cannot be reasonably predicted better than by random chance is generated. This means that the particular outc ...
is aimed at being an improvement on the 'standard'
linear congruential generator
A linear congruential generator (LCG) is an algorithm that yields a sequence of pseudo-randomized numbers calculated with a discontinuous piecewise linear equation. The method represents one of the oldest and best-known pseudorandom number generat ...
. These are based on a generalisation of the
Fibonacci sequence
In mathematics, the Fibonacci numbers, commonly denoted , form a sequence, the Fibonacci sequence, in which each number is the sum of the two preceding ones. The sequence commonly starts from 0 and 1, although some authors start the sequence from ...
.
The Fibonacci sequence may be described by the
recurrence relation
In mathematics, a recurrence relation is an equation according to which the nth term of a sequence of numbers is equal to some combination of the previous terms. Often, only k previous terms of the sequence appear in the equation, for a paramete ...
:
:
Hence, the new term is the sum of the last two terms in the sequence. This can be generalised to the sequence:
:
In which case, the new term is some combination of any two previous terms. ''m'' is usually a power of 2 (''m'' = 2
''M''), often 2
32 or 2
64. The
operator denotes a general
binary operation
In mathematics, a binary operation or dyadic operation is a rule for combining two elements (called operands) to produce another element. More formally, a binary operation is an operation of arity two.
More specifically, an internal binary op ...
. This may be either addition, subtraction, multiplication, or the
bitwise
In computer programming, a bitwise operation operates on a bit string, a bit array or a binary numeral (considered as a bit string) at the level of its individual bits. It is a fast and simple action, basic to the higher-level arithmetic oper ...
exclusive-or operator (
XOR
Exclusive or or exclusive disjunction is a logical operation that is true if and only if its arguments differ (one is true, the other is false).
It is symbolized by the prefix operator J and by the infix operators XOR ( or ), EOR, EXOR, , , ...
). The theory of this type of generator is rather complex, and it may not be sufficient simply to choose random values for and . These generators also tend to be very sensitive to initialisation.
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
In computing, a linear-feedback shift register (LFSR) is a shift register whose input bit is a linear function of its previous state.
The most commonly used linear function of single bits is exclusive-or (XOR). Thus, an LFSR is most often a s ...
'' or GFSR. The
Mersenne Twister
The Mersenne Twister is a general-purpose pseudorandom number generator (PRNG) developed in 1997 by and . Its name derives from the fact that its period length is chosen to be a Mersenne prime.
The Mersenne Twister was designed specifically to re ...
algorithm is a variation on a GFSR. The GFSR is also related to the
linear-feedback shift register
In computing, a linear-feedback shift register (LFSR) is a shift register whose input bit is a linear function of its previous state.
The most commonly used linear function of single bits is exclusive-or (XOR). Thus, an LFSR is most often a ...
, or LFSR.
Properties of lagged Fibonacci generators
The maximum period of lagged Fibonacci generators depends on the binary operation
. If addition or subtraction is used, the maximum period is (2
''k'' − 1) × 2
''M''−1. If multiplication is used, the maximum period is (2
''k'' − 1) × 2
''M''−3, or 1/4 of period of the additive case. If bitwise xor is used, the maximum period is 2
''k'' − 1.
For the generator to achieve this maximum period, the polynomial:
:''y'' = ''x''
''k'' + ''x''
''j'' + 1
must be
primitive
Primitive may refer to:
Mathematics
* Primitive element (field theory)
* Primitive element (finite field)
* Primitive cell (crystallography)
* Primitive notion, axiomatic systems
* Primitive polynomial (disambiguation), one of two concepts
* Pr ...
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
''The Art of Computer Programming'' (''TAOCP'') is a comprehensive monograph written by the computer scientist Donald Knuth presenting programming algorithms and their analysis. Volumes 1–5 are intended to represent the central core of comp ...
'':
:(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.
It has been suggested that good ratios between and are approximately the
golden ratio
In mathematics, two quantities are in the golden ratio if their ratio is the same as the ratio of their sum to the larger of the two quantities. Expressed algebraically, for quantities a and b with a > b > 0,
where the Greek letter phi ( ...
.
["Uniform random number generators for supercomputers"](_blank)
Richard Brent, 1992
Problems with LFGs
In a paper on four-tap shift registers,
Robert M. Ziff
The name Robert is an ancient Germanic given name, from Proto-Germanic "fame" and "bright" (''Hrōþiberhtaz''). Compare Old Dutch ''Robrecht'' and Old High German ''Hrodebert'' (a compound of '' Hruod'' ( non, Hróðr) "fame, glory, ho ...
, 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
Marsaglia is a '' comune'' (municipality) in the Province of Cuneo in the Italian region Piedmont, located about southeast of Turin and about east of Cuneo.
References
External links
Official website
Cities and towns in Piedmont
C ...
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
,
, and
, simply given by the generator itself ... While these correlations are spread over the size
of the generator itself, they can evidently still lead to significant errors.".
"Four-tap shift-register-sequence random-number generators"
Robert M. Ziff, Computers in Physics, 12(4), Jul/Aug 1998, pp. 385–392 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.
The initialization of LFGs is a very complex problem. The output of LFGs is very sensitive to initial conditions, and statistical defects may appear initially but also periodically in the output sequence unless extreme care is taken. Another potential problem with LFGs is that the mathematical theory behind them is incomplete, making it necessary to rely on statistical tests rather than theoretical performance.
Usage
* Freeciv uses a lagged Fibonacci generator with for its random number generator.
* The Boost library includes an implementation of a lagged Fibonacci generator.
* Subtract with carry, a lagged Fibonacci generator engine, is included in the C++11
C++11 is a version of the ISO/ IEC 14882 standard for the C++ programming language. C++11 replaced the prior version of the C++ standard, called C++03, and was later replaced by C++14. The name follows the tradition of naming language versio ...
library.
* The Oracle Database
Oracle Database (commonly referred to as Oracle DBMS, Oracle Autonomous Database, or simply as Oracle) is a multi-model database management system produced and marketed by Oracle Corporation.
It is a database commonly used for running online ...
implements this generator in its DBMS_RANDOM package (available in Oracle 8 and newer versions).
See also
Wikipedia page ' List of random number generators' lists other PRNGs including some with better statistical qualitites:
* Linear congruential generator
A linear congruential generator (LCG) is an algorithm that yields a sequence of pseudo-randomized numbers calculated with a discontinuous piecewise linear equation. The method represents one of the oldest and best-known pseudorandom number generat ...
* ACORN generator
* Mersenne Twister
The Mersenne Twister is a general-purpose pseudorandom number generator (PRNG) developed in 1997 by and . Its name derives from the fact that its period length is chosen to be a Mersenne prime.
The Mersenne Twister was designed specifically to re ...
* Xoroshiro128+
* FISH (cipher)
The FISH (FIbonacci SHrinking) stream cipher is a fast software based stream cipher using Lagged Fibonacci generators, plus a concept from the shrinking generator cipher. It was published by Siemens
Siemens AG ( ) is a German multinatio ...
* Pike
* VIC cipher
References
Toward a universal random number generator
G.Marsaglia, A.Zaman
{{DEFAULTSORT:Lagged Fibonacci Generator
Pseudorandom number generators
Fibonacci numbers