I've read an appnote from TI (slaa338) that describes a technique for generating "for real" (as opposed to "pseudo") random numbers. It exploits the somewhat exotic clock subsystem of the MSP430 to achieve this goal. Does anyone know of a technique that can be implemented on an AVR (I'm interested in the XMega's in particular) for generating "for real" random numbers?
|
|
How bad do you to use the XMega? If the crypto and random number generation are a big part of your project, Atmel's SecureAVR series has a hardware random number built in, and is designed for cryptographic applications. Regardless, I doubt that you'll find a random seed source that has a good distribution. You'll want to run it through a pseudo random number generator a few times As long as you start with a different seed every time, this will give you a nice set of random numbers. An LGC is a quick and easy pseudo random generator:
|
|||||||
|
|
Connect up the ADC to a hardware noise source and use software to "whiten" the random numbers as needed. Here's an AVR based project that does this: Leon's Mini Portable Random Number Generator (mPRNG) Depending on how cryptographically secure it needs to be, you could use the noise of a floating analog input or the "internal temperature sensor" as your randomness seed instead of external hardware. |
|||||
|
|
Another trick for generating a random seed, is to count the number of clock cycles until an external event. For example if this is a device to be used by a person, count the number of clock cycles until he presses the 'go' button, and use that as the random seed. |
|||||
|
|
To be sure to not restart with the same sequence, I use somme byte in the eeprom :
This give quite good random, and does not cost much in programme/memory. |
|||||
|
|
Have you looked at using something like randomSeed()? - used in the Arduino IDE You can use this function to sample a floating (free) analog pin on the atmel AVR, it then uses the value to create an arbitrary starting point for the pseudo random number function - random(). The value created by random() may be a pseudo random number - but the arbitrary starting point created by randomSeed() should be as real a random number/value as you can get. |
|||||||||
|