# Circuit to randomly light one LED or another

I am attempting to make a cheap and simple "quantum-ish" coin flip circuit. My idea is to use something like an SR latch driving two LEDs, and have the initialization be driven by some random event.

I will be cross-posting in the physics stack exchange as for what could qualify as a quantum trigger, but my initial thought was to compare the resistance of two LDRs in the dark as a "quantum" event. So essentially the SR latch would be powered up and whichever LDR had a slightly lower/higher resistance would drive the latch to initialize in that state and stay there until power is removed.

What would a circuit like that look like? Is there any way I can tune it so that the probability is approximately 50-50 for each LED.

• Is the coin flip triggered by a human button push. If yes, use the duration of the button push to randomize. – Mattman944 Jun 25 '19 at 19:25
• If it is truly a Quantum state. Just looking at it flips the expected state. But you may want it simple or lots of Entropy. – Tony Stewart Sunnyskyguy EE75 Jun 25 '19 at 19:34
• I suspect if you take 2 LDRs and measure the resistances, you will get the same result every time, because of slight manufacturing differences. – Simon B Jun 26 '19 at 8:02

edit: Above may have Nch-Pch square symmetry error with temp so added divide by 2 and raised clock to 100kHz and removed inverter so it selects random binary phase from LPF filtered rising clock.

Improved Sim with noise injected for test on supply.

Use any button switch to ground.

Extra LED's with Shift Register to see history.

Clock frequency is so fast compared to human response, it is random.

• A leaky cap with 1MΩ resistance will offset the 50-50 by Rf/1MΩ = 1kΩ/1MΩ=0.1%
• 10kΩ Series to protect CMOS input.
• Small signal diode to prevent V- on rapid button pushing.
• A good ceramic cap is 50 seconds=ΩF so 100nF = 500 MΩ but then dirt flux is less than this.
• Do you feel lucky guessing the next or how many times to get 9 same in a row?
• The latching half is a great start. I'd like to have the signal half run in a slightly more random manner though. Is it possible to have the output of the schmitt be generated by whether the resistance of one photoresistor is higher than the other? – Will Stedden Jun 25 '19 at 22:29
• Try it out and see how long it takes to get consecutive 0’s and 1’s . It should be equal. For a string of 8 or 9 and don’t use anything high impedance unless just a switch with a shunt cap. Adding a random clock won’t add any entropy. – Tony Stewart Sunnyskyguy EE75 Jun 25 '19 at 22:31
• Yes it’s possible to use differential Photo resistors but photo diodes are much more accurate in the same ambient. Noise is a concern with lighting flicker unless daylight blocking filters are used with IR light – Tony Stewart Sunnyskyguy EE75 Jun 25 '19 at 22:41
• The schmitt trigger oscillator duty cycle may not be exactly 50%, I recommend a divide by 2 before the F/F D input. – Mattman944 Jun 25 '19 at 22:55
• The entropy for this simulation is very poor. Just hold the button down for more than a few seconds each time. Generation of random numbers is hard and even physical circuits such as this will 'sync' to minute fluctuations in the power supply or chip current paths. I'd suggest that the best solution would be to use a small MCU using the internal RC clock generator. An ATTiny85 can be had for less than \$1 and produces quite acceptable results. – Jack Creasey Jun 26 '19 at 5:04

Creating a random number generator with adequate entropy is very very hard.
Using any simple logic solution is likely doomed since the isolation between elements and limited PSRR means its easy to end up with some form of sync that degrades the entropy result.

The classical way has been to generate random noise and then A/D or level detect this to get good entropy. The solutions here tend to be complex, but do deliver reasonable results.
I'm not sure how effective an LDR would be (it's a single typically N based material with no tunneling capability), in the past I've used either photodiodes or reverse biased transistors to provide the quantum effect. See here and here.

If you are looking for an easy, cheap and reliable digital implementation, you might try this RC oscillator based solution.

I've used a modification of the 'jitter' library with an ATTiny85 where the WDT and System 'RC' clocks are separate. I used a 'Digispark' initially but now use the ATTiny85 running at 3V using a TL431 shunt regulator to give good PSRR. It's an easy solution to lay out on a PCB, and I don't use the ATTiny for any other purpose, just as a RNG. The nice part of the solution is that I can use the Arduino PRNG with a fixed seed value for debug and switch to the TRNG using an input pin. The results are very encouraging and you can view the Entropy site information here.