In another post I asked about how to randomly seed a randomSeed() call for use with the random() function. While messing with diodes and resistors on an analog input of the Arduino it occurred to me that the 10 bits of analog input must be pretty sensitive to noise. And if the analog in is not connected to anything it is floating and prey to any stray electrical noise in the vicinity. So I simply do this:
// This is my setup for my sketch, but anyway bit 5 becomes an analog input
DDRC = 0xCF; // PortC, Turn most analog inputs to digital outputs, except for bits 4 and 5
// This stuff will be better inside a function of course, but basically
// I read three times the presumably more noisy 3 LSB bits of the ADC
// and form them into a single 9 bit (range 0...511) number.
iRandom1 = analogRead(5) & 0x7 ;
delay (10) ;
iRandom2 = (analogRead(5) & 0x7) << 3 ;
delay (10) ;
iRandom3 = (analogRead(5) & 0x7) << 6 ;
delay (10) ;
iRandom = iRandom1 + iRandom2 + iRandom3 ;
Serial.println(iRandom, DEC);
No doubt it is not a good random number generator, but it is probably a good randomSeed maker for "non technical projects" which have a spare ADC pin and which require a different starting point every time the Arduino is switched on.
You have the advantage that you don't have to add any hardware or connect to the internet.
I'm prepared to be shot down in flames, so fire away!
Attached are a couple of runs as an Excel graph