Does anybody know how to generate random number using 8051?
I have had a quick look at the pseudo-random number generator here: http://www.programmersheaven.com/zone5/cat27/30104.htm It looks as if it is a Fibonacci implementation of a 32-bit LFSR. Fibonacci implementations are common in hardware, but in software they are more complex (and slower) than Galois (prononced Gal-whar) implemenations. In software, Fibonacci implementation become more complex as the number of taps increases whereas Galios implementation can implement any number of taps without any extra complexity. In general, a large number of taps is desirable because it makes the output "more random".
As you just want numbers 0..127, why not just use a lookup table - so each "call" to rand() just returns the next entry?
As you just want numbers 0..127, why not just use a lookup table - so each "call" to rand() just returns the next entry? But, Ivan said that he was out of code memory. Ivan: if you are really desparate for space, it would be possible to implement an 8 or 7 bit LFSR. The advantage of a 7-bit LFSR is that it would give you values in the range 1..127 without any further processing. On the other hand the sequence would not be very random - you will get all the values 1..127 exactly once before the sequence repeats. If that is what you want, I can probably write a generator in about five minutes!