Subtractive generator: Difference between revisions

m
corrected a typo.
m (added whitespace to the task's preamble.)
m (corrected a typo.)
Line 17:
The authors of ''Freeciv''   ([http://svn.gna.org/viewcvs/freeciv/trunk/utility/rand.c?view=markup utility/rand.c])   and ''xpat2'' (src/testit2.c)   knew another problem:   the low bits are less random than the high bits.
 
The subtractive generator has a better reputation than the &nbsp; [[linear congruential generator]], &nbsp; perhaps because it holds more statestates. &nbsp; A subtractive generator might never multiply numbers: &nbsp; this helps where multiplication is slow. &nbsp; A subtractive generator might also avoid division: &nbsp; the value of &nbsp; <big><big><math> r_{(n-i)} - r_{(n-j)} </math></big></big> &nbsp; is always between &nbsp; <big><big><math> -m </math></big></big> and <big><big><math> m </math></big></big>, &nbsp; so a program only needs to add &nbsp; <big><big><math> m </math></big></big> &nbsp; to negative numbers.
 
The choice of &nbsp; <big><big><math> i </math></big></big> &nbsp; and &nbsp; <big><big><math> j </math></big></big> &nbsp; affects the period of the generator.