3 ms·
I'm curious how he tackled the issue of the random number generator in the arduino. The fairly simple one included in avr-libc would be prone to repeating afte
by simcop2387 15y ago
I'm curious how he tackled the issue of the random number generator in the arduino. The fairly simple one included in avr-libc would be prone to repeating after a power off.
There's two ways I can think of to deal with that, save the state in the EEPROM so that it doesn't repeat, or add a hardware based random number generator, i'd like to know which he ended up going with.
- jgrahamc 15y agoIt's in the source code on github (https://github.com/jgrahamc/simonoids/blob/master/simonoids.ino https://github.com/jgrahamc/simonoids/blob/master/simonoids....). I use a combination of reading the microsecond time (hoping that there'll be some variation because of the ADC conversion time), reading floating ADC inputs and storing random values from previous execution in the EEPROM: // Set the random number generator from a seed generated by reading from a // floating analog pin or two long seed = micros(); for ( int i = 0; i < 1000; ++i ) { seed += analogRead(0); seed += analogRead(1); seed += micros(); } // Use EEPROM locations to store a value from the random number generator so that from // switch on to switch on the seed will change even if the above loop always gave the same // value for ( int i = 0; i < 4; ++i ) { seed += (long)EEPROM.read(i); } randomSeed(seed); for ( int i = 0; i < 4; ++i ) { EEPROM.write(i, random(0,255)); }
- simcop2387 15y agoAh I had missed the link to the github code in there. I like the idea of reading some floating analog pins to get some entropy.