Guys...... I need to get an idea how to generate random numbers using C-langugae? Would it be possible to implement such a thing efficiently using moderate microcontrollers like PIC or AVR series!
Look for "linear congruential method".
This is one of the most common and simple methods for generating random numbers with uniform distribution.
Regards
Use the following code for a linear congruential generater. It uses a 32-bit global unsigned integer. It must be 32 bits! For the PIC C18 compiler you can use unsigned long. You can set the seed with setSeed(seed) and get a random number with rand().
Code:
unsigned long x;
void setSeed(unsigned long seed) {
x=seed;
}
unsigned long rand() {
x = 1103515245 * x + 12345;
return x & 0x3FFFFFFF;
}
Slorn -- dwengo... gets you started with microcontrollers!
Use your A/D converter as a source for producing random number(seed) by connecting one of the A/D input via a resistor to GND and read the result without filter or summing