ober WROTE:Just my sudden thought, kind of agree with generating the number from key press.
Though is not really random, but if the microcontroller is running at 20MHz, and each instruction is executed at 200ns. If changing the number at 7-segment take a few instructions, it will take around 1us to 2us. Basically no one cannot see and also predict the number that will appear on 7seg when it release the keypress.
Therefore it become random
Myke Predko has a smarter way to generate random number. Page 128 of my "Evil Genius" book has an example on how to generate random number using TMR0. The result is an integer between 0 and 255:
OPTION = 0b01001111; // Run TMR0 From PIC MCU Clock
;
;
; when random number is needed:
;
i = TMR0; // Save TMR0 Value
if (i > 100) // Convert TMR0 Value to Decimal
LCDWrite((i / 100) + '0', 1);
else // No Hundreds to Display
LCDWrite(' ', 1);
if (i > 10)
{
i = i % 100; // Not Greater than 10
LCDWrite((i / 10) + '0', 1);
}
else
LCDWrite(' ', 1);
LCDWrite((i % 10) + '0', 1);
As the program is copyrighted. I can only extract a portion out of the whole program.
Allen