LFSR (pseudo-random)

Cheap pseudo-random numbers from a handful of XOR gates.

When to use it

A linear-feedback shift register cycles through almost every value in a wild-looking order for the cost of a shift register and a few XORs. It's the go-to for pseudo-random test data, scramblers, cheap counters, PRBS patterns and CRCs.

How it works

Shift left every clock, feeding a new bit that's the XOR of a few chosen taps. With a maximal-length tap set, an N-bit register visits all 2^N-1 non-zero states before repeating. This 8-bit version taps bits 8, 6, 5, 4 for a period of 255.

Gotchas

Try it

Runs on our simulator, edit the code and press Run to see the waveform.

Open & fork in the playground → Ship the verified version: lfpga add lfpga_lfsr

The runnable example above is a teaching version. The libfpga library ships a hardened, parameterised, CI-tested module (lfpga_lfsr) for production use.