


Just put it in a loop and let the synthesis tool figure out the logic: module fibonacci_lfsr_nbitĭata_next = Īssign stage = !stage ^ stage Īn LFSR is often the first port of call. Repeating Morgan's example below, but to get a 5 bit number each cycle: module fibonacci_lfsr_5bit(Įdit: Added a new version below which doesn't require you to do the math. However, if you want a new number every clock cycle the other option is to unroll the loop and predict what the number will be in N cycles. If you want an N bit random number you have to run the LFSR for N cycles. The number of bits in the LFSR only set how many values you get before the sequence repeats. Shifting the Galois output ten times to the right, we would find the same output of the Fibonacci LFSR.As noted in Morgan's answer this will only produce a single random bit. Just for fun, let's try it with a mirroring output. In order to obtain this kind of coupled outputs, the taps of the Galois register must be the counterparts of the ones of the Fibonacci register. The seed choice is not relevant since it would introduce only a shift in the output. In such a register, all possible states are visited - except the null state, which would make the register collapse in a sequence of 0s. The two types of LFSR produce the same result - minus a reflection and a translation - when the taps are the ones generating a maximally long LFSR.
