If you were eating a soup from a bowl with 500ml of soup taking 25ml spoonfuls, and the rain replaced the volume that you ate at the same rate as you ate it, how many spoon fulls would it take for the soup to be completely replaced with water? Also, when that happens, would it still be the same soup?

  • TranquilTurbulence@lemmy.zip
    link
    fedilink
    English
    arrow-up
    2
    ·
    5 days ago

    You’re right. I just ran rbinom 1E7 times and found that the probability of over drawing soup molecules is a bit too high for my taste.

    When there’s only 1 left, you usually end up drawing 0 or 1 molecule. However, in rare cases, it can be higher, such as 2, 3, 4… molecules.

    About 92% was 0, and 7.7% was 1, but the others were not negligible! There’s about 0.3% probability of over drawing, which is way too high for a simulation as serious as this one. In this quick test, there were 20 incidents where rbinom wanted to pull out 4 soup molecules when only 1 was available. We can’t have that, now can we!

    • NeatNit@discuss.tchncs.de
      link
      fedilink
      arrow-up
      2
      ·
      5 days ago

      In python the closest I could find was (untested): sum(random.sample([1, 0], spoon_size, counts=[soup_count, water_count]))

      But this would create an intermediate list of length spoon_size which is not a good idea.

        • TranquilTurbulence@lemmy.zip
          link
          fedilink
          English
          arrow-up
          1
          ·
          5 days ago

          Hmmm… The description certainly fits. Just by eye-balling the graphs, they look very different from what I got, but I guess that’s just the expected result of running rbinom about a 6 million times. With a smaller simulation, it might not have been so apparent. Also, that’s what you get for skipping the maths and vibing the code without thinking too much about the details. Well, at least i got this far with absolutely minimal effort. :D

          It appears that I need to switch to a better distribution. Thanks for looking into this mystery!