??? 10/29/09 12:42 Read: times Msg Score: 0 +1 Good Answer/Helpful -1 Overrated |
#170179 - This method might work...you can try it.... Responding to: ???'s previous message |
Hi Roberto Torri,
1. Write a small program on PC using VB/VC/etc. that generates 256 random numbers between 1 and 256. Besure that any number is not repeated. 2. Put these 256 random numbers in your MCS51 code as a table(array). 3. Load MCS51 timer in Mode2 and start the timer. Never reset this timer. 4. Wait for any event (as Erik has mentioned), Keyboard press/UART Charachter/etc. Note the TLx value. 5. Use the TLx Value as a Pointer in that table. And you will have a true random number. This Method is based on external event to happen. The event can be truly random in nature, here are some methods to use it: A. User presses a key, Read the value of TLx, and that is a random number between 0~255. B. You receive a specific charachter from PC during the normal course of Serial Communication, Read TLx, that is the random number. C. If your product is having an analog Input, then, whenever the analog value reaches a specific value, reset the Timer TLx=00. See to it that you reset the timer in more than 5 minutes, otherwise you will be able to predict the value. You can also Load TLx with any number of your choice when the analog input reaches a specific value. You can use any 2 digits your wife (or girl-friend's) phone number and tell her that..she will be happy. All the Timer TLx values (mentioned in A,B,C) can be used as pointer to the table mentioned in Step 1. I think that should be giving you a fairly good random number. Of course there are many more ways to generate a random number, it depends upon how much amount of randomness do you need? (Somebody has asked you this question before). If you want a truly, truly random number, then the method mentioned by Kai is the best one. P.N. I have not read all the posts in this thread, Sorry, if I have repeated the post or neglected some of them... I think this thread is having a hot discussion, so I wanted to relax everybody's nerves. Sorry, if I offended anybody. |