Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
11/13/02 12:45
Read: times


 
#32386 - RE: generating random words 8051
If you need help with a random number generator here are a few ideas.

If you are writing in C language there is most likely a library function for this. (i.e. in Keil C51 it is called rand).

If writing in assembly language you can check out the random number routine at this site. In the case of the assembler routine you get a number from 1 -> 65535, so you need to divide that by the number of words in your word list and utilize the remainder as the word selector.

With any random number generator there is still the issue getting it "seeded" properly so that you don't always start from the same place. This comes about because the algorithms that are used for random number generation always generate the next number off the last number that was provided. And it is typical that the memory location where this last number was stored is not "randomly" initialized at power up. There is a simple method to do this that I have used before. After you look at the seeding method you may very well decide to use it as the word selector instead.

Here is an example seeding method for the random number generator applied to your game idea. When the 8051 first powers up start a timer going with as high a speed clocking as possible. (8 bit timer works for seeding to 256 start places, so 16 bit timer is better). Do not select the first word until after the player has pressed a "start" button. At the time the start button is pressed simply read the timer current value and use that to seed the random number generator. Once the random number generator is seeded please set yourself a flag that says you can skip the seeding on subsequent presses of the "start" button. (This works because the player will have variable reaction time of engaging power until the time the button is pressed.

You can see now, particularly if the timer is always available and is 16 bits wide, that it would be possible to simply use the timer value as the random number itself.

Hope this info helps.
Michael Karas


List of 10 messages in thread
TopicAuthorDate
generating random words 8051            01/01/70 00:00      
RE: generating random words 8051            01/01/70 00:00      
mahmood            01/01/70 00:00      
RE: generating random words 8051            01/01/70 00:00      
RE: generating random words 8051            01/01/70 00:00      
RE: generating random words 8051            01/01/70 00:00      
RE: generating random words 8051            01/01/70 00:00      
RE: generating random words 8051, Kunal            01/01/70 00:00      
Deja vu            01/01/70 00:00      
RE: Deja vu            01/01/70 00:00      

Back to Subject List