I am currently trying to build a Random Number Generator using an arduino.
My plan is to build a circuit which generates white noise (which I have done), connect that to the arduino, and use analog read to collect random numbers from the white noise.
The white noise generator looks good on the oscilloscope, but I cannot seem to figure out the next step.
I have tried various graphing and "arduino oscilloscope" programs but the waveform on the arduino does not seem to look like the waveform on the oscilloscope, is it possibly incompatible in some way? Frequency to high, low? I am getting something on the arduino scope programs, but it doesn't look right.
What would be the best way to process the white noise into random numbers? Would it be better to use digital read insead of analog read, and read the bits into a byte? Or perform some kind of smoothing or randomising algorithm on the data before using it?
If it is good idea to process white noise to get random numbers it would be widely referenced in statistics literature so maybe you want to start there. Once you find a algorithm from the statistical experts and scholars you could ask here how to implement them.
Do you want to create a random number every time with the white noise ?
Normally, an analog input is used to get a random value, and that is used to feed a true random algoritme. The white noise would be used just once.
You could capture more analog inputs, in case the analog signal is not very random. I use a LDR on one input and the unconnected other analog inputs and combine them. White noise would be a lot better than a LDR ofcourse.
It turns out, that the analog inputs are used for every bit, so it is just like the code by robtillaart in this item.
For my project, I used XTEA so it will fit into a ATmega8.
In the package that I transmit is a random number, for which I use reading the analog channel.
@robtillaart:
I tried your code, it seemed to work well, however it failed the tests I did. I used a program called ENT:
To test both the number generated from white noise and the number generated from just background radiation (nothing connected to the analog pin).
They were both the same, and both non-random.
@ Erdin@
I would like to do whichever is the most random. Ideally, I would have liked to prove the concept using only numbers generated from white noise, but that is not looking like it's possible. I may have to use the white noise as a seed to a pseudo random generator? I could then test the numbers generated with numbers seeded using the system time, and see if the white noise produces a noticable improvement.
I think continuously seeding from white noise would be more random than seeding just once, would it not?
If I'm not mistaken, is that true random code not just taking the input from an analog port as "random" noise and using that as a seed? If so, I could combine that with white noise on the analog port, I suppose?
I think the true random code is taking its input from the circuit described here connected to an analog pin: http://robseward.com/misc/RNG2/
and note that its input must be 12V. 5V won't work.
Hello JackStone, I made some random number hardware in the past at Intel. Please describe your white noise hardware for us. In particular, what is its output impedance, output voltage range, and output bandwidth? Do you have photos of oscilloscope traces of good looking white noise you made. Please post the digital numbers you get that seem bad from your existing software work.
@el_supremo:
That circuit looks quite similiar to the one that I am using, so it should work fairly ok. That is an excellent link too, thanks for that.
@AmbiLobe: Really, you worked for intel developing RNG hardware? That's impressive!
My electronics skills are quite basic to be honest, my main skill is in programming. The circuit I am using is this one: http://electro-music.com/forum/phpbb-files/whitenoise_969.jpg
It's a very simple circuit, but it seems to be producing the correct results.
I attached a trace from my oscilloscope. The yellow is the noise going into the amp, the blue is the amplified noise coming out, I think I may have an issue with that, I'm still debugging it.
I also attached a text file with my random numbers in it, which failed the ENT tests.
I have made some changes to my noise generator, and I am now certain that it is producing white noise. However, the numbers being picked up by the arduino (using robtillaart's code) are not random, they have a very predictable pattern.
I have enclosed the log file. Anyone have any idea on this?
I checked my code and there is some "sawtooth" behaviour in it, the number of shifts when building up the number increases. These are typically the most significant bits
That should not have any effect, still here an alternative with a constant shift. If this shows the same distribution the shift is not the cause.
void setup()
{
Serial.begin(115200);
}
void loop()
{
uint32_t x = getRandomUL();
Serial.println(x);
}
uint32_t getRandomUL()
{
uint32_t x = 0;
for (uint8_t i = 0; i < 32; i++)
{
x |= (analogRead(A0) & 0x01);
x <<= 1;
}
}
uint8_t getRandomByte()
{
uint8_t x = 0;
for (uint8_t i = 0; i < 8; i++)
{
x |= (analogRead(A0) & 0x01);
x <<= 1;
}
return x;
}