Generating random numbers with hardware noise?

In response to this question over on the programming board: http://forum.arduino.cc/index.php?topic=325219

What would be a simple way to generate noisy bits in hardware? It doesn't matter of the noise is not perfectly 50/50 high and low, because you can take successive pairs of bits and generate a fair coin toss that way.

Can you use a photodetector on an analog input and take the bottom bit? A transistor being driven too hard? A sloppy oscillator? An antenna picking up environmental noise?

I'm not an electronics person - I'm a programmer - what's a solution I could put on a breadboard and use?

--EDIT--

I'm not looking for a cryptographically secure system - I can see there's a lot of discussion on that and it's not a simple problem. So instead, just looking for something good enough to initialise a game. Small and easy to do.

Would just sticking a length of wire in an analog input as an antenna and using VonNeuman's whitening work pretty well most of the time?

A noisy electronic component is a Zener diode operating at the knee voltage.

A single resistor... http://hal9k.ifsc.usp.br/~matias/floss/orb/info/ORB_Index.html

However, the method does not work with AVR processors. The sample-and-hold capacitor does not have enough capacitance. An external capacitor may get the method working.

A sloppy oscillator?

I assume from that question you have not bothered to follow the link I provided. Following it does require just a single mouse click. Oh well. I guess I’m done here.

Grumpy_Mike: A noisy electronic component is a Zener diode operating at the knee voltage.

Yes, better still use the BE junction of a small transistor in its zener breakdown region, passing about 1 mA through it in the reverse direction. Follow it with a LP filter to get the bandwidth you require and an amplifier.

Russell.

A button.

Just ask your game player to press a start button. This will occur at some random time after power-up and millis() can be used to seed the random number generator.

MorganS: A button.

Just ask your game player to press a start button. This will occur at some random time after power-up and millis() can be used to seed the random number generator.

better use micros() / 4 to have a finer granularity.

Have you seen this:- http://holdenc.altervista.org/chua/

1 Like

Thanks for that fascinating link Mike.

Russell.

Proper shielding is a good idea so nearby phones transmitting can't influence the signal being amplified. If you want to protect against three-letter-agencies then it gets hard.

Check that you random signal is actually present (the time-averaged amplitude should be within certain bounds - if not then a component may have failed or a wire come loose)

Is this for cryptographic purposes?

If you liked the other link, you might like this as well:

https://web.jfet.org/hw-rng.html

Not that the difference is all too great :)

syntaxterror:
If you liked the other link, you might like this as well:

https://web.jfet.org/hw-rng.html

Not that the difference is all too great :slight_smile:

That’s what I suggested in reply #4 except they haven’t used an LP filter.

Russell.

russellz: That's what I suggested in reply #4 except they haven't used an LP filter.

Russell.

Indeed. Just wanted to throw it in there - I was always impressed by how simple and with how few components the guy managed to make this work.

[quote author=Coding Badly date=1432536168 link=msg=2246773] I assume from that question you have not bothered to follow the link I provided. Following it does require just a single mouse click. Oh well. I guess I'm done here.[/quote]

+1

@PaulMurrayCbr, why are you trying to add "hardware" when the built-in AVR hardware can provide a true, tested random seed? Check the Entropy software... You claim to be a software guy, after all.

He knows this. He asks out of interest, on the basis of a question asked in another thread.

syntaxterror: He knows this. He asks out of interest, on the basis of a question asked in another thread.

I don't think he knows this. He said this in the other thread:

I know that the Java "SecureRandom" class works by starting up a number of threads and timing them. Could this entropy library be doing the same thing? Starting up some processor threads (or an equivalent - yeah I know the AVR is single threaded but I'm looking for clues).

Perhaps the entropy library has a specific "stop doing whatever it is you do for the time being" that you might need to call.

...as if he hadn't even looked at the library. Then he starts this thread with this question:

Can you use a... sloppy oscillator?

This is exactly what the Entropy library is doing. He says he's looking for clues, but he obviously hasn't looked at the clues that were provided.

Horse to water, etc.

This guy has a solution which he claims to be very high quality that could be interfaced with an Arduino also, using a comparator and an op amp multiplying Johnson noise, though it looks like there is PC code that is used to produce the final output and that would have to be ported into the microcontroller:

https://github.com/waywardgeek/infnoise

MorganS: A button.

Just ask your game player to press a start button. This will occur at some random time after power-up and millis() can be used to seed the random number generator.

This is my favorite method, as long as there is someone there to press a button, any button event will do. Start, stop, up, left, whatever.

Bear in mind that method is very likely to have bias. For things like blinky lights it makes no difference. For things like random dice it can be a problem.

OK, so the button method is biased towards a particular range of numbers. You're probably going to get numbers between 1000ms and 2000ms, for example. So this means your random number generator is only getting about 1000 different values for the START of the random sequence. So there's only about 1000 different games that can be played with that device, under the assumed conditions. You could use micros() and get about 5000 different starting points.

The random numbers produced by the generator after it's seeded don't have bias. What is the problem?