In order to get a very good unpredictable random number generator to run on the sam3x8e, here's what I'm thinking of doing:
Step 1: In the firmware, use the Mersenne Twister algorithm (for example this code) which will take up about 2 - 3 kB of RAM
Step 2: When the firmware is written to the microcontroller, each individual microcontroller will get a unique random 32-Bit value stored in its Flash. When the chip boots up, it will read the 32-Bit seed from the Flash and use this 32- Bit number (along with other data) to seed the generator.
Step 3: When the firmware boots up on the microcontroller, the execution time of the "loop" function will be timed in microseconds for the first three thousand iterations. So the first iteration might be 832 microseconds, and the second might be 754 microseconds, and the third might be 783 microseconds. I will perform an XOR operation each time, like this:
global_boolean_seed_is_ready = false;
void loop(void)
{
static unsigned counter = 0u;
static uint32_t time = 0u;
// Do lots of stuff in here like access I2C and RS232
if ( 3000u == counter )
{
global_boolean_seed_is_ready = true;
}
else
{
time ^= micros();
++counter;
}
}
Step 4: I will read the aforementioned random 32-Bit value from the Flash and XOR it with the 32-Bit value gotten from Step 3, and this is what I'll use to seed the Mersenne Twister algorithm.
Step 5: As the future values of the Mersenne Twister algorithm can be predicted if we see 624 consecutive outputs, I will never allow as many as six hundreds outputs in a row. Instead I will only allow about 300 consecutive values before reseeding the generator.
If I implement this, I think I will get a very good random number generator running on my sam3x83.
P.S. Two years ago, I wrote a program in C to predict future output of the Mersenne twister, and I want to take the time to integrate it into the "Die Harder" program which is widely used for testing random number generators.