Go Down

### Topic: Using an Arduino to process white noise into Random Numbers (Read 11422 times)previous topic - next topic

#### JackStone

##### Aug 21, 2013, 01:34 am
Hello,

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?

#### wwbrown

#1
##### Aug 21, 2013, 05:20 am
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.

#### robtillaart

#2
##### Aug 21, 2013, 12:30 pm
Try this sketch, it fetches one bit of the white noise per sample and merges this to a unsigned long / byte
Code: (not tested) [Select]
`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) << i);  }}uint8_t getRandomByte(){  uint8_t x = 0;  for (uint8_t i = 0; i < 8; i++)  {    x |= ((analogRead(A0) & 0x01) << i);  }  return x;}`
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

#### Erdin

#3
##### Aug 22, 2013, 01:30 am
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.

#### robtillaart

#4
##### Aug 22, 2013, 01:13 pm
Quote
to feed a true random algoritme

I would like to have that one ...

best I could find sofar is the external service described here - http://forum.arduino.cc/index.php?topic=38091.msg282225#msg282225 -

And because you just don't know how many others users there are it will be quite unrepeatable ...
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

#### Erdin

#5
##### Aug 22, 2013, 02:34 pm
User perhop replied me in an item about encryption:
http://forum.arduino.cc/index.php?topic=175504.msg1302452#msg1302452

He uses this:
https://github.com/chicoplusplus/arduino/tree/master/libraries/TrueRandom
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.

#### JackStone

#6
##### Aug 22, 2013, 05:02 pm
Thank you very much for the replies!

@robtillaart:
I tried your code, it seemed to work well, however it failed the tests I did. I used a program called ENT:
http://www.fourmilab.ch/random/

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?

Thanks again!

#### el_supremo

#7
##### Aug 22, 2013, 06:06 pm
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.

Pete
Don't send me technical questions via Private Message.

#### robtillaart

#8
##### Aug 22, 2013, 08:30 pm
Thanks Pete for the link, bookmarked
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

#### AmbiLobe

#9
##### Aug 23, 2013, 12:46 pm
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.

#### JackStone

#10
##### Aug 24, 2013, 09:32 pm

@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.

#### JackStone

#11
##### Aug 26, 2013, 11:16 pm
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?

#### robtillaart

#12
##### Aug 27, 2013, 10:29 am

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.

Code: (not tested) [Select]
`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;}`
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

#13
##### Aug 29, 2013, 10:00 am
He uses this:
https://github.com/chicoplusplus/arduino/tree/master/libraries/TrueRandom

TruyRandom is worthless.  Stay away from it.