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
- Never seed it all-zeros, that's a dead state it can never leave. Reset to any non-zero value (this one uses 0xFF).
- Only specific tap sets give the full period; the wrong ones cycle early. Use a known maximal-length table, or the LFSR generator.