Worked Example: A Digital Dice Roller
← All articles

Worked Example: A Digital Dice Roller

5 min

A free-running source of 'random' numbers

A linear-feedback shift register driven continuously by a fast CLOCK cycles through its states so quickly relative to human reaction time that whatever value it holds the instant someone presses a button looks effectively unpredictable, even though the whole thing is completely deterministic underneath.

Freezing a value on button press

Feed the LFSR's SHIFT4 output into a loadable register whose Load input comes from a debounced button through an edge detector — so the register captures and holds whatever the LFSR's state happened to be at the exact instant of the press, ignoring the LFSR's continued cycling until the next press.

LFSRREGbutton (Load)RemapSEG7

Mapping 4 bits onto six dice faces

An LFSR's 4 output bits span 0–15, but a die only has six faces. A small comparator-based remap — subtract 6, or 12, whenever the value is 6 or greater, or 12 or greater — folds the range down to 0–5, and adding a fixed 1 turns that into the familiar 1–6. Feed the result into a SEG7 block to display it.

Try it yourself

Build the full chain in the circuit editor — free-running LFSR, debounced button, edge-triggered load into a register, range remap, SEG7 display — and press the button repeatedly to confirm the displayed digit changes unpredictably but always lands between 1 and 6.

Build a dice roller in the circuit editor →