Random Number Generator: Difference between revisions

m
[unchecked revision][unchecked revision]
(→‎Pseudorandom number generators: Linear Feedback Shift Registers)
Line 67:
 
=== Linear feedback shift register ===
A Linear Feedback Shift Register (LFSR) is a simple way to generate a very long sequence of random numbers, given a non-zero seed. The idea is as follows: an ''n''-bit LFSR has ''n'' 'registers', each containing one bit (either 0 or 1). Initially, all the registers are filled with the bits from an ''n'''-bit seed. For each next value to be generated, take some bits from certain registers and XOR them together. Feed the resulting binary value into the left-most register, shifting all bits one position to the right. The bit that is shifted out of the LFSR on the right-most side is the generated random bit.
 
The sequence of bits that an LFSR can produce will eventually repeat, but by choosing the XOR'ed bits carefully the period of the LFSR can be increased to up to 2<sup>n</sup> - 1 bits. This means that after a sequence of 2<sup>n</sup> - 1 bits, the same sequence will be returned. However, this is a property that all pseudo-random number generators have: without changing the seed, they will eventually repeat themselves.
Anonymous user