
This project implements a 5-bit pseudo-random number generator using a Linear Feedback Shift Register (LFSR).
The LFSR continuously updates on every clock cycle using XOR feedback taps:
feedback = lfsr[4] ^ lfsr[2];
When the correct 2-bit key (10) is applied, the LFSR behaves normally and generates a pseudo-random sequence.
When an incorrect key is applied, the feedback path is poisoned by shifting zeros into the register instead of the feedback bit. Over time, the LFSR drains to zero and the random generator stops functioning correctly.
The current LFSR value is captured into a sample register whenever the SAMPLE input is asserted.
The sampled value is then mapped into a user-defined range using modulo logic:
generated_number = sampled % (max_value + 1);
The generated number is:
The 7-segment display uses active-high segment outputs.
ui[4:0] = maximum output value (0–31)uio[5] = KEY_0uio[6] = KEY_1uio[7] = SAMPLEuio[4:0] = generated random numberuo[6:0] = 7-segment display segmentsApply the correct key:
KEY = 10
Then:
ui[4:0]SAMPLEuio[4:0]The generated number should remain within:
0 to MAX_VALUE
Apply any incorrect key value.
The LFSR feedback path becomes poisoned and the internal state eventually drains to:
00000
After enough clock cycles:
| # | Input | Output | Bidirectional |
|---|---|---|---|
| 0 | MAX_0 | SEG_A | RNG_0 |
| 1 | MAX_1 | SEG_B | RNG_1 |
| 2 | MAX_2 | SEG_C | RNG_2 |
| 3 | MAX_3 | SEG_D | RNG_3 |
| 4 | MAX_4 | SEG_E | RNG_4 |
| 5 | SEG_F | KEY_0 | |
| 6 | SEG_G | KEY_1 | |
| 7 | SAMPLE |