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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
10/29/09 13:33
Read: times


 
#170181 - Watch out for distribution problems for small ranges
Responding to: ???'s previous message
One issue with having a random number generator that produces values between 0 to 255 is that you get a broken distribution if you need values of a smaller range, and makes use of modulo.
The following shows the number of matches from modulo 2 and up to modulo 25.
2: 128 128
3: 86 85 85
4: 64 64 64 64
5: 52 51 51 51 51
6: 43 43 43 43 42 42
7: 37 37 37 37 36 36 36
8: 32 32 32 32 32 32 32 32
9: 29 29 29 29 28 28 28 28 28
10: 26 26 26 26 26 26 25 25 25 25
11: 24 24 24 23 23 23 23 23 23 23 23
12: 22 22 22 22 21 21 21 21 21 21 21 21
13: 20 20 20 20 20 20 20 20 20 19 19 19 19
14: 19 19 19 19 18 18 18 18 18 18 18 18 18 18
15: 18 17 17 17 17 17 17 17 17 17 17 17 17 17 17
16: 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16
17: 16 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15
18: 15 15 15 15 14 14 14 14 14 14 14 14 14 14 14 14 14 14
19: 14 14 14 14 14 14 14 14 14 13 13 13 13 13 13 13 13 13 13
20: 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 12 12 12 12
21: 13 13 13 13 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12
22: 12 12 12 12 12 12 12 12 12 12 12 12 12 12 11 11 11 11 11 11 11 11
23: 12 12 12 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11
24: 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 10 10 10 10 10 10 10 10
25: 11 11 11 11 11 11 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10

Simulating a 6-sided dice, there would be a 2.4% greater chance to get 1, 2, 3 or 4 in relation to 5 or 6.

Simulating a 20-sided dice, there would be a 10% greater chance to get 1..16 compared to 17..20.

So pseudo-random or not, the code must make sure that the max range of the random generator works well for the specific requirements, or perform a correction. In the example of a 6-sided dice with a random number generator that produces values 0..255, the values 252 to 255 should be ignored.

The problem is the same when using the timer directly.

Having a larger range for the generator will just reduce the percentage error in distribution.

List of 67 messages in thread
TopicAuthorDate
Random numbers            01/01/70 00:00      
   How random?            01/01/70 00:00      
   extract?            01/01/70 00:00      
      Time for Google            01/01/70 00:00      
      Extract            01/01/70 00:00      
   you can't            01/01/70 00:00      
      a very good way to get random numbers            01/01/70 00:00      
      Interesting anecdote regarding timers:            01/01/70 00:00      
      Periodicity            01/01/70 00:00      
   Just curious...            01/01/70 00:00      
      Didn't search first!            01/01/70 00:00      
         New Information not searchable            01/01/70 00:00      
            Using life itself as part of its computational matrix...            01/01/70 00:00      
               Sure it is            01/01/70 00:00      
         Show me any real new thread...            01/01/70 00:00      
            But...            01/01/70 00:00      
               It really means...            01/01/70 00:00      
                  No "Come In!", but a "Go Home!"            01/01/70 00:00      
                     Exclusive information...            01/01/70 00:00      
                        Thanks...            01/01/70 00:00      
                        First and ONLY Time I reply to this            01/01/70 00:00      
                           Completely ridiculous might be a bit strong            01/01/70 00:00      
                           Lazyness...            01/01/70 00:00      
                              ...is already ignored            01/01/70 00:00      
                                 But we restrict ourselves!            01/01/70 00:00      
                                    No, you are restricting the definition of "help"            01/01/70 00:00      
                                       Your propaganda again...            01/01/70 00:00      
                                          People ARE posting code snippets etc            01/01/70 00:00      
                                             Come on, how many do so?            01/01/70 00:00      
                                                Do what?            01/01/70 00:00      
                                          The limiting factor            01/01/70 00:00      
                                             Mixing subjects            01/01/70 00:00      
                                                Not a valid answer            01/01/70 00:00      
                                                   Are we poluting this thread?            01/01/70 00:00      
                                                      Yes, but Roberto has gone already...            01/01/70 00:00      
                              true for good schools, but not for diploma mills            01/01/70 00:00      
                     Balance            01/01/70 00:00      
                        Warding people away is no good policy either            01/01/70 00:00      
                           Bully for seeing problems with negative votes???            01/01/70 00:00      
                              Its his will            01/01/70 00:00      
                              Its just a biginning!            01/01/70 00:00      
                                 Still extrapolating            01/01/70 00:00      
                                    Relativity?            01/01/70 00:00      
                                    Extrapolating What            01/01/70 00:00      
                                       Not a valid conclusion!            01/01/70 00:00      
                                       Still extrapolating            01/01/70 00:00      
                           Wrong link?            01/01/70 00:00      
                              link to link            01/01/70 00:00      
                                 But nothing about fear of 8052.com?            01/01/70 00:00      
                                    At least,...            01/01/70 00:00      
   This method might work...you can try it....            01/01/70 00:00      
      Unnecessary complication!            01/01/70 00:00      
         Watch out for distribution problems for small ranges            01/01/70 00:00      
         Yes..But for added randomness, use the table            01/01/70 00:00      
            Incorrect - the table adds nothing!            01/01/70 00:00      
               Quality often important even for simple devices            01/01/70 00:00      
                  can be dangerous            01/01/70 00:00      
                     Bus arbitration needs a lot            01/01/70 00:00      
            HUH????            01/01/70 00:00      
      he can't            01/01/70 00:00      
      Modulating the /INT0 input by a simple noise generator            01/01/70 00:00      
         Post-processing needed            01/01/70 00:00      
            What interrupt?            01/01/70 00:00      
               Both interrupt or gating possible            01/01/70 00:00      
                  Full agree with everything you wrote!            01/01/70 00:00      
         Addendum...            01/01/70 00:00      
   Google as a resource?            01/01/70 00:00      

Back to Subject List