Introduction: True Random Number Generator TRNG (4-Bit)
The goal of this little project was to build a random number generator that didn’t rely on calculations to supply a random number, as computers do, and try to get the number as random or as close to random as possible.
Step 1: How It Works
The 4 Bit TRNG relies on the bounce that occurs when mechanical contacts close or open.
The number of bounces seems to be random and by connecting the contacts of a relay to the clock input of a 4 bit binary or BCD counter, a random number can be generated.
By adding another relay and connecting its contacts to the clock input of a J-K flip flop, that is wired up to toggle, an up/down counter can be used by connecting the Q output of the J-K flip-flop to the up/down input of the counter which would randomly select counting up or counting down and thus increasing the randomness.
Bounce -> http://en.wikipedia.org/wiki/Switch
Step 2: Parts List
1 x 74LS191N (Binary Synchronous up/down counter)
1 x SN7476N (Dual J-K flip-flops with preset and clear)
1 x 1K Resistor
2 x 2K2 Resistors
2 x RKT-5 Relays (5V / DIP / DPDT)
2 x 1N4004 Diodes
2 x Momentary on switches
1 x LED
1 x Led Display (or 4 LEDS with resistors)
74LS191N -> http://search.datasheetcatalog.net/key/74LS191N
Step 3: Schematic and Working (in a Nut Shell)
The left switch activates the left relay (press and release).
It’s NO (normally open) contacts closes and opens and bounces a random number of times which toggles the J-K flip-flop.
The Q output from the J-K flip-flop is connected to the up/down input on the counter and randomly sets count up or down.
The Led lights up if the counter is set to count down.
The right switch activates the right relay (press and release).
It’s NO contacts closes and opens and bounces a random number of times which the counter counts.
The Led display displays the random 4 bit number in hex (not shown in the schematic, connected to QA to QD).
Another way to create a random number is while holding the right switch down, push and release the left switch and then release the right switch.
This also works because the 74LS191 can generate a false clock if the up/down input changes (left switch) while the clock input is low (right switch) and thus, in combination with contact bounce, counting erratically.
Step 4: Connecting It to an Micro Controller or Other Project
By replacing the switches with transistors and resistors, an micro controller could take control of the 4 Bit TRNG and read out the random number at QA to QD.
Step 5: Possible Variations
A few possible variations to this 4 bit TRNG could be:
Connecting the N.C. (normally closed) contacts to GND for even more bounce.
Connecting the unused sides of the relays to the used side which would randomly add or counteract the number of contact bounces.
Omitting the left relay and connecting the unused side of the right relay to the J-K flip-flop.