Good day, everyone! I try to randomize numbers on AVR Asm (atmega128). So I need initialize value at the beginning and note that for asm x86 developers use "rdtsc" instruction. Is that possible to init some random init value like rdtsc at AVR architecture? Is that possible to use different init value? Thanks and regards.
2 Answers
I see, you know it, but to emphasize once again, you can't use any timer/counter value as random number generator. You can use it only as a source for the pseudo random algorithm seed number.
In order to do it, you need a timer/counter that counts fast and continuously and human that actually performs as a random event generator.
Without human interaction, it is not possible to get random number seed using timer or counter.
In the computers, the human randomizes the moment of the program start.
The counter is not actually so important. The only requirement to it is to run much more faster then the human reaction time. Several kilohertz is a acceptable frequency. This way, you can use for example some of the timers, configured to the fastest possible frequency, or even a simple software counter incremented on every main program loop (of course if the program is fast enough).
If your device supports real time clock, use it. This way you will get better randomization, because the RTC runs even if the whole devide is switched off.
This way, the human provided switch ON will provide random moment event.
In all cases, the algorithm that you will use to generate the pseudo random numbers is much more important than the seed generation approach.
So, make is as simple and stupid as possible and concentrate on the pseudo random number generator.