Lagged Fibonacci generator
   HOME

TheInfoList



OR:

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 number generation, random n ...
. 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 is generated that cannot be reasonably predicted better than by random chance. This means that the particular ou ...
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 gener ...
. These are based on a generalisation of the
Fibonacci sequence In mathematics, the Fibonacci sequence is a Integer sequence, sequence in which each element is the sum of the two elements that precede it. Numbers that are part of the Fibonacci sequence are known as Fibonacci numbers, commonly denoted . Many w ...
. 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 parameter ...
: :S_n = S_ + S_ Hence, the new term is the sum of the last two terms in the sequence. This can be generalised to the sequence: :S_n \equiv S_ \star S_ \pmod, 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'' = 2''M''), often 232 or 264. The \star 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, a binary operation ...
. 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 operat ...
exclusive-or operator (
XOR Exclusive or, exclusive disjunction, exclusive alternation, logical non-equivalence, or logical inequality is a logical operator whose negation is the logical biconditional. With two inputs, XOR is true if and only if the inputs differ (one ...
). 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'' 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 choice of a Mersenne prime as its period length. The Mersenne Twister was created specifically to address most of ...
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#Boolean functions, linear function of its previous state. The most commonly used linear function of single bits is exclusive-or (XOR). Thus, ...
, or LFSR.


Properties of lagged Fibonacci generators

The maximum period of lagged Fibonacci generators depends on the binary operation \star. 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 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 multi-volume monograph written by the computer scientist Donald Knuth presenting programming algorithms and their analysis. it consists of published volumes 1, 2, 3, 4A, and 4 ...
'': :(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 summation, sum to the larger of the two quantities. Expressed algebraically, for quantities and with , is in a golden ratio to if \fr ...
."Uniform random number generators for supercomputers"
Richard Brent, 1992


Problems with LFGs

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 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 Cuneo (; ; ; ) is a city and in Piedmont, Italy, the capital of the province of Cu ...
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_, x_, and x_, simply given by the generator itself ... While these correlations are spread over the size p = max(a, b, c, \ldots ) 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.


Example implementation

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 #define R (607) #define S (273) #include uint64_t X uint64_t gen_rand()


Usage

*
Freeciv ''Freeciv'' is a single-player video game, single- and multiplayer video game, multiplayer turn-based strategy game for workstations and personal computers inspired by the proprietary software, proprietary ''Civilization (series), Sid Meier's ...
uses a lagged Fibonacci generator with for its random number generator. * The
Boost library Boost is a set of library (computing), libraries for the C++ programming language that provides support for tasks and structures such as linear algebra, pseudorandom number generator, pseudorandom number generation, multithreading, image proces ...
includes an implementation of a lagged Fibonacci generator. *
Subtract with carry Subtract-with-carry is a pseudorandom number generator: one of many algorithms designed to produce a long series of random-looking numbers based on a small amount of starting data. It is of the lagged Fibonacci type introduced by George Marsaglia ...
, a lagged Fibonacci generator engine, is included in the
C++11 C++11 is a version of a joint technical standard, ISO/IEC 14882, by the International Organization for Standardization (ISO) and International Electrotechnical Commission (IEC), for the C++ programming language. C++11 replaced the prior vers ...
library. * The
Oracle Database Oracle Database (commonly referred to as Oracle DBMS, Oracle Autonomous Database, or simply as Oracle) is a proprietary multi-model database management system produced and marketed by Oracle Corporation. It is a database commonly used for ru ...
implements this generator in its DBMS_RANDOM package (available in Oracle 8 and newer versions).


See also

Wikipedia page '
List of random number generators Random number generators are important in many kinds of technical applications, including physics, engineering or mathematical computer studies (e.g., Monte Carlo simulations), cryptography and gambling (on game servers). This list includes many ...
' lists other PRNGs including some with better statistical qualities: *
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 gener ...
* 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 choice of a Mersenne prime as its period length. The Mersenne Twister was created specifically to address most of ...
*
Xoroshiro128+ Xorshift random number generators, also called shift-register generators, are a class of pseudorandom number generators that were invented by George Marsaglia. They are a subset of linear-feedback shift registers (LFSRs) which allow a particularly ...
*
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 in 1993. FISH is quite fast in software and has ...
*
Pike Pike, Pikes or The Pike may refer to: Fish * Blue pike or blue walleye, an extinct color morph of the yellow walleye ''Sander vitreus'' * Ctenoluciidae, the "pike characins", some species of which are commonly known as pikes * ''Esox'', genus of ...
*
VIC cipher The VIC cipher was a pencil and paper cipher used by the Soviet Union, Soviet spy Reino Häyhänen, codenamed "VICTOR". If the cipher were to be given a modern technical name, it would be known as a "straddling bipartite monoalphabetic substitut ...


References


Toward a universal random number generator
G.Marsaglia, A.Zaman {{DEFAULTSORT:Lagged Fibonacci Generator Pseudorandom number generators Fibonacci numbers