Subtractive generator: Difference between revisions

m
added whitespace to the task's preamble.
m (used a larger font to make the formulae, italics, super- and subscripts, and symbols easier to read, added other whitespace and highlighting to the task's preamble..)
m (added whitespace to the task's preamble.)
Line 2:
 
A ''subtractive generator'' calculates a sequence of [[random number generator|random numbers]],   where each number is congruent to the subtraction of two previous numbers from the sequence.
<br>The formula is
<big><big><math> r_n = r_{(n - i)} - r_{(n - j)} \pmod m </math></big></big>
 
<br>The formula is
<big><big><math> r_n = r_{(n - i)} - r_{(n - j)} \pmod m </math></big></big>
for some fixed values of &nbsp; <big><big><math> i, </math></big></big> &nbsp; <big><big><math> j, </math></big></big> &nbsp; and &nbsp; <big><big><math> m</math></big></big>, &nbsp; all positive integers.
 
Supposing that &nbsp; <big><big><math>i > j</math></big></big>, &nbsp; then the state of this generator is the list of the previous numbers from &nbsp; <big><big><math> r_{n-i} </math></big></big> &nbsp; to &nbsp; <big><big><math> r_{n - 1}</math></big></big>.
 
Many states generate uniform random integers from &nbsp; <big><big><math> 0 </math></big></big> &nbsp; to &nbsp; <big><big><math> m-1</math></big></big>, &nbsp; but some states are bad. &nbsp; A state, filled with zeros, generates only zeros. &nbsp; If &nbsp; <big><big><math> m </math></big></big> &nbsp; is even, &nbsp; then a state, filled with even numbers, generates only even numbers. &nbsp; More generally, &nbsp; if &nbsp; <big><big><math> f </math></big></big> &nbsp; is a factor of &nbsp; <big><big><math> m</math></big></big>, &nbsp; then a state, filled with multiples of &nbsp; <big><big><math> f</math></big></big>, &nbsp; generates only multiples of &nbsp; <big><big><math> f</math></big></big>.
 
All subtractive generators have some weaknesses. &nbsp; The formula correlates &nbsp; <big><big><math> r_n</math></big></big>, &nbsp; <big><big><math> r_{(n-i)} </math></big></big> &nbsp; and &nbsp; <big><big><math> r_{(n-j)}</math></big></big>; &nbsp; these three numbers are not independent, as true random numbers would be.