Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Back Room
  4. The Law of Averages.

The Law of Averages.

Scheduled Pinned Locked Moved The Back Room
game-devquestionlounge
20 Posts 8 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Nish Nishant

    Michael Dunn wrote: Try 3.6 million The bigger the number the more evenly the distributions :-) Tell him to try 2 ;-) Nish


    Author of the romantic comedy Summer Love and Some more Cricket [New Win] Buy it, read it and admire me :-)

    J Offline
    J Offline
    jkgh
    wrote on last edited by
    #11

    And then you can bring in the CLT! Alice thought that running very fast for a long time would get you to somewhere else. " A very slow kind of country!" said the queen. "Now, here , you see, it takes all the running you can do, to keep in the same place".

    1 Reply Last reply
    0
    • P peterchen

      The stdlib: rand() implementations are usually not "that good". They are ok for making things lok random, but for statistic purposes they are out. Knuth 1 still has the best introduction to PRNG IMO.


      Back in the days before yer Gighertz and Teraflops there was something we old timers called paranoia. Andrew Torrance, The Lounge   [sighist]

      J Offline
      J Offline
      jkgh
      wrote on last edited by
      #12

      Even box-muller routines are frowned upon. See Wilmott.com Alice thought that running very fast for a long time would get you to somewhere else. " A very slow kind of country!" said the queen. "Now, here , you see, it takes all the running you can do, to keep in the same place".

      1 Reply Last reply
      0
      • P peterchen

        kevnar wrote: After 360 rolls the average number of times each combonation was rolled was exactly 10.0. Exactly! If this happens more than once in your life, there's something wrong. honestly.


        Back in the days before yer Gighertz and Teraflops there was something we old timers called paranoia. Andrew Torrance, The Lounge   [sighist]

        K Offline
        K Offline
        Kevnar
        wrote on last edited by
        #13

        Try it for yourself. I made a 6 by 6 grid with 1 to 6 on the top and 1 to 6 down the side and then I rolled two dice and stacked a hypothetical chip in the square at the rolled coordinates. Then I took the average numerber of chips in each of the 36 grid squares. It was all over the place in the first hundred trials or so, but eventually it averaged out to an even 10.0 for 360 rolls. I tried it over and over and it always came out to 10.0. I was so amazed that I double checked my code to make sure I hadn't made a mistake. It's all good. Can it be wrong in exactly the same way over and over again? Why not throw away a dime? I throw away ten pennies all the time.

        C P M 3 Replies Last reply
        0
        • K Kevnar

          Try it for yourself. I made a 6 by 6 grid with 1 to 6 on the top and 1 to 6 down the side and then I rolled two dice and stacked a hypothetical chip in the square at the rolled coordinates. Then I took the average numerber of chips in each of the 36 grid squares. It was all over the place in the first hundred trials or so, but eventually it averaged out to an even 10.0 for 360 rolls. I tried it over and over and it always came out to 10.0. I was so amazed that I double checked my code to make sure I hadn't made a mistake. It's all good. Can it be wrong in exactly the same way over and over again? Why not throw away a dime? I throw away ten pennies all the time.

          C Offline
          C Offline
          Chris Losinger
          wrote on last edited by
          #14

          it's not that it's wrong (it's absolutely correct - each combo has the same probability) so much as that it's just highly improbable (or lucky, if you prefer) that you'd see it with so few samples. -c


          Cheap oil. It's worth it!

          Image Processing - just like mom used to make.

          1 Reply Last reply
          0
          • K Kevnar

            Try it for yourself. I made a 6 by 6 grid with 1 to 6 on the top and 1 to 6 down the side and then I rolled two dice and stacked a hypothetical chip in the square at the rolled coordinates. Then I took the average numerber of chips in each of the 36 grid squares. It was all over the place in the first hundred trials or so, but eventually it averaged out to an even 10.0 for 360 rolls. I tried it over and over and it always came out to 10.0. I was so amazed that I double checked my code to make sure I hadn't made a mistake. It's all good. Can it be wrong in exactly the same way over and over again? Why not throw away a dime? I throw away ten pennies all the time.

            P Offline
            P Offline
            peterchen
            wrote on last edited by
            #15

            int board[6][6];

            void Play()
            {
            srand(time(NULL)); // <-- re-seed the generator
            memset(board, 0, sizeof(board));
            for(int i=0; i<360; ++i) {
            int x = rand() % 6;
            int y = rand() % 6;
            board[x][y] += 1;
            }
            }

            **typical results:

            15     3     9     4     8     8
             8    12     5    18    13    11
             5    11     8    12     9     5
            13    13     8    11    15     8
            15     9    10    14    12    11
             8    10     9     8    12    10
            

            12 6 10 9 9 7
            8 12 11 12 15 5
            12 5 15 10 8 11
            5 14 7 15 8 12
            10 13 9 15 6 7
            7 11 13 15 10 6

            These distributions are "normal", you will see similar if you use real dice. of course if you're lucky, you can get an all-tens, but this is highly unlikely.


            Back in the days before yer Gighertz and Teraflops there was something we old timers called paranoia. Andrew Torrance, The Lounge   [sighist]**

            K 1 Reply Last reply
            0
            • K Kevnar

              Try it for yourself. I made a 6 by 6 grid with 1 to 6 on the top and 1 to 6 down the side and then I rolled two dice and stacked a hypothetical chip in the square at the rolled coordinates. Then I took the average numerber of chips in each of the 36 grid squares. It was all over the place in the first hundred trials or so, but eventually it averaged out to an even 10.0 for 360 rolls. I tried it over and over and it always came out to 10.0. I was so amazed that I double checked my code to make sure I hadn't made a mistake. It's all good. Can it be wrong in exactly the same way over and over again? Why not throw away a dime? I throw away ten pennies all the time.

              M Offline
              M Offline
              Michael Dunn
              wrote on last edited by
              #16

              kevnar wrote: I tried it over and over and it always came out to 10.0. You're seeding your random number generator with the same value every time ;P :-D --Mike-- Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines! My really out-of-date homepage Sonork-100.19012 Acid_Helm

              K 1 Reply Last reply
              0
              • P peterchen

                int board[6][6];

                void Play()
                {
                srand(time(NULL)); // <-- re-seed the generator
                memset(board, 0, sizeof(board));
                for(int i=0; i<360; ++i) {
                int x = rand() % 6;
                int y = rand() % 6;
                board[x][y] += 1;
                }
                }

                **typical results:

                15     3     9     4     8     8
                 8    12     5    18    13    11
                 5    11     8    12     9     5
                13    13     8    11    15     8
                15     9    10    14    12    11
                 8    10     9     8    12    10
                

                12 6 10 9 9 7
                8 12 11 12 15 5
                12 5 15 10 8 11
                5 14 7 15 8 12
                10 13 9 15 6 7
                7 11 13 15 10 6

                These distributions are "normal", you will see similar if you use real dice. of course if you're lucky, you can get an all-tens, but this is highly unlikely.


                Back in the days before yer Gighertz and Teraflops there was something we old timers called paranoia. Andrew Torrance, The Lounge   [sighist]**

                K Offline
                K Offline
                Kevnar
                wrote on last edited by
                #17

                You guys don't get what I'm saying. I'm not saying all the grid squares were ten, I'm saying the average was always 10. Add all these numbers up and divide by 36. It's gonna be 10, or pretty close to it. The more trial rolls you do, the closer it is to the perfect average(number of trials divided by 36, 10 in the case of 360 rolls). The same holds true for real dice. Although I have no desire to sit there and roll real dice all night. Why not throw away a dime? I throw away ten pennies all the time.

                P 1 Reply Last reply
                0
                • M Michael Dunn

                  kevnar wrote: I tried it over and over and it always came out to 10.0. You're seeding your random number generator with the same value every time ;P :-D --Mike-- Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines! My really out-of-date homepage Sonork-100.19012 Acid_Helm

                  K Offline
                  K Offline
                  Kevnar
                  wrote on last edited by
                  #18

                  Hardy har. Gee how could I have forgoten that? ;P My seed was set to the system clock, which gives you at least a pretty good pseudo-random number. Why not throw away a dime? I throw away ten pennies all the time.

                  1 Reply Last reply
                  0
                  • K Kevnar

                    You guys don't get what I'm saying. I'm not saying all the grid squares were ten, I'm saying the average was always 10. Add all these numbers up and divide by 36. It's gonna be 10, or pretty close to it. The more trial rolls you do, the closer it is to the perfect average(number of trials divided by 36, 10 in the case of 360 rolls). The same holds true for real dice. Although I have no desire to sit there and roll real dice all night. Why not throw away a dime? I throw away ten pennies all the time.

                    P Offline
                    P Offline
                    peterchen
                    wrote on last edited by
                    #19

                    Ah, ok that makes more sense, but I am still :confused: (could you please post code? I sometimes have trpoubles with plain english ;) If you throw the dice exactly 360 times, and add a chip to the board each time, you will have 360 chips on the board - even if you throw the dice *away* and just stack them all on one quare. If you add all fields up and divide by 36, you will get 10. (is it this what you're referring to?) Now I'm puzzled that you sometimes do *not* get a perfect 10.... might be there's an roundin error involved, or I still don't get what you mean... :confused: :cool:


                    Back in the days before yer Gighertz and Teraflops there was something we old timers called paranoia. Andrew Torrance, The Lounge   [sighist]

                    K 1 Reply Last reply
                    0
                    • P peterchen

                      Ah, ok that makes more sense, but I am still :confused: (could you please post code? I sometimes have trpoubles with plain english ;) If you throw the dice exactly 360 times, and add a chip to the board each time, you will have 360 chips on the board - even if you throw the dice *away* and just stack them all on one quare. If you add all fields up and divide by 36, you will get 10. (is it this what you're referring to?) Now I'm puzzled that you sometimes do *not* get a perfect 10.... might be there's an roundin error involved, or I still don't get what you mean... :confused: :cool:


                      Back in the days before yer Gighertz and Teraflops there was something we old timers called paranoia. Andrew Torrance, The Lounge   [sighist]

                      K Offline
                      K Offline
                      Kevnar
                      wrote on last edited by
                      #20

                      You know what? You're right. That explains it. It's just simple math. D'uh! No wonder it was so consistent. :-O Thanks for helping me look into it. :laugh: Why not throw away a dime? I throw away ten pennies all the time.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups