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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
11/15/06 01:49
Read: times


 
Msg Score: +1
 +1 Good Answer/Helpful
#128002 - This problem needs more thought
Responding to: ???'s previous message
Dan,

It seems that Maarten has hit on the reason your random number generator was always giving even numbers, and it seems that by removing the unnecessary initialization of R2, R3, and R4 in your 'bin_to_bcd' routine, you have found a way to make it work.

Although we now understand what was wrong and have a fix, it's not a very good fix because the same even-only problem will appear and disappear in the future whenever you make changes to the program that affect the timing of the main loop. This is not a good thing.

I was thinking that you should arrange the hardware to produce an interrupt whenever somebody pushes the switch. The handler for that interrupt would capture the timer value and write it to a location in RAM that the main loop will then subsequently read and display.

That would be better than the current implementation, for the reason explained above, but I still don't think the resulting numbers would be truly random. Depending on the mix of instructions in the main loop, I think there would still be a tendency to see more even numbers than odd numbers (or the other way around) at the time of the interrupt. Maarten's suggestion of throwing away the LSB of the result would fix that problem. Then we're left wondering if the remaining upper bits are truly random.

My thinking is really fuzzy on this point, but I'd have to guess that the answer is "nope, even though the upper bits may look random to a casual observer, their distrubution still depends on the mix of instructions in the main loop." It seems that to make this thing really work right, the timer has to be running asynchronously with respect to the CPU clock, as well as somewhat faster.

Can somebody come up with a different slant on this that makes it easier to understand and talk about? I'm starting to confuse myself.

-- Russ


List of 53 messages in thread
TopicAuthorDate
Pseudo-Random Number Generator Strangeness            01/01/70 00:00      
   Problem lies in BCD converter            01/01/70 00:00      
      Why?            01/01/70 00:00      
         I like see the program 0-255            01/01/70 00:00      
            0-255 SSD Counter            01/01/70 00:00      
               Clarity?            01/01/70 00:00      
               Thanks for the reply            01/01/70 00:00      
                  WRONG            01/01/70 00:00      
                  Not necessarily each line            01/01/70 00:00      
                     re useful            01/01/70 00:00      
      FIXED            01/01/70 00:00      
         Yes ... but WHAT fixed it???            01/01/70 00:00      
   Hints for a smaller program            01/01/70 00:00      
      Great!            01/01/70 00:00      
         More hints            01/01/70 00:00      
   Count the cycles            01/01/70 00:00      
      Good guess, Maarten!!!            01/01/70 00:00      
      Brilliant, Maarten!            01/01/70 00:00      
      Wait Period            01/01/70 00:00      
         Wait does not make up            01/01/70 00:00      
            Makes Sense            01/01/70 00:00      
               why 'debounce'            01/01/70 00:00      
                  ARGHHHHH eric            01/01/70 00:00      
                     Jez, please            01/01/70 00:00      
               Divide by 2            01/01/70 00:00      
   This problem needs more thought            01/01/70 00:00      
      Interrupts don't help            01/01/70 00:00      
         Thanks, Maarten            01/01/70 00:00      
   A Suggestion            01/01/70 00:00      
      use TH1            01/01/70 00:00      
         Use TL0            01/01/70 00:00      
            agreed somewhat, but            01/01/70 00:00      
   Misunderstanding            01/01/70 00:00      
      Just SSD values            01/01/70 00:00      
         Thanks for the reply            01/01/70 00:00      
         Dan if like            01/01/70 00:00      
         7-Segment Connexions            01/01/70 00:00      
            Will Comment Soon...            01/01/70 00:00      
               Famous last words!            01/01/70 00:00      
               A More Excellent Way            01/01/70 00:00      
                  some do flowcharts, before they code            01/01/70 00:00      
   An Update            01/01/70 00:00      
      Typo            01/01/70 00:00      
      Still misleading comment            01/01/70 00:00      
         Fine            01/01/70 00:00      
   Dan this program needs            01/01/70 00:00      
      Tautology?!            01/01/70 00:00      
         Overkill            01/01/70 00:00      
            a typical example of follwing rules to the letter            01/01/70 00:00      
               Exception to the rule?            01/01/70 00:00      
            Not only comments, but format as well            01/01/70 00:00      
               8051 Simulator            01/01/70 00:00      
                  simulator support            01/01/70 00:00      

Back to Subject List