| ??? 04/19/00 15:26 Read: times |
#2263 - RE: programming a memory game |
There is an even easier way to do the random numbers since your application is looking for equal random distribution among the numbers 1 through 4.
Since you need a random number that is a power of two, you can merely strip all but the last two bits of whatever count is in the timer/counter. Another neat trick that is unnecessary for your example is useful if you didn't have a nice power of 2. Say you needed an even random numbers distribution among the numbers from 1 to 37. All you need to do is put the timer in mode 2 (auto reload) and initialize the counter reload to (256-37) and let it free-run. When you need a random number, grab the counter value and subtract it from 256 (to convert back to 1 relative). -Jay C. Box I'll send you some example code later but the idea is to set up the timer in mode 2. In this mode, the timer/counter can only count at most through 00:FF instead of 0000:FFFF. The unused byte of the counter is instead used to load a "RELOAD" count. When the timer/counter clicks past FF, it reloads that value and starts counting to FF again. So here's the trick. Since you need only |
| Topic | Author | Date |
| programming a memory game | 01/01/70 00:00 | |
| RE: programming a memory game | 01/01/70 00:00 | |
| RE: programming a memory game | 01/01/70 00:00 | |
RE: programming a memory game | 01/01/70 00:00 |



