3 ms·
It's in the source code on github (https://github.com/jgrahamc/simonoids/blob/master/simonoids.ino https://github.com/jgrahamc/simonoids/blob/master/simonoids..
by jgrahamc 15y ago
It'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.