Linear Feedback Shift Register (LFSR)


  • LFSR can be used to generate pseudo-random numbers using a seed value, which is the initial value required to start the random number generation process

A 2 step process

shift() shifts all bits to the left by one, except for the least significant bit (LSB). The LSB is determined as the XOR of the most significant bit (MSB) and the tap bit before the shift. The tap bit specifies the index of the bit used in the XOR operation. The shift() function returns the LSB after performing the shift. This new LSB bit is also known as the feedback bit.

generate() calls shift() times. It collects the returned bits in order from most significant to least significant and then converts these bits back into a decimal value. This decimal value represents the pseudo-random number generated by the LFSR.