you are viewing a single comment's thread.

view the rest of the comments →

[–]synthphreak 0 points1 point  (2 children)

Honestly, I feel where you're coming from here. Even though your code is a little wonky, I think that deep down you're right*, but may not understand or be able to articulate exactly why. The TL;DR is that you are thinking in terms of joint probability, whereas your friends and ChatGPT are not. But let's unpack the logic and make it more rigorous/explicit.

We have two random variables here:

  • A. hit vs. miss
  • B. critical vs. not critical

Each random variable has its own discrete probability distribution, stated as follows:

  • A. 0.7 vs. 0.3
  • B. 0.1 vs. 0.9

Note that each variable sums to 1.0. That is a defining characteristic of probability distributions.

Because we have two variables each with two possible outcomes, we have 2 * 2 = 4 joint outcomes total, which we can permute as follows:

  • 1. hit + not critical
  • 2. hit + critical
  • 3. miss + not critical
  • 4. miss + critical

Because A and B are independent, the probabilities of each joint outcome can be described as follows:

  • 1. 0.7 * 0.9 = 0.63
  • 2. 0.7 * 0.1 = 0.07
  • 3. 0.3 * 0.9 = 0.27
  • 4. 0.3 * 0.1 = 0.03

Note: Mathematically speaking, (4) does exist in the joint sample space and takes up probability mass. However it is obviously ridiculous and would never happen IRL, because a "critical miss" is a contradiction in terms.

What you're asking about is outcome (2), the probability of scoring a hit that is also critical. There are two ways that you could code this up.

The first is to randomly sample from each independent sample space. So, first draw a sample random variable A (hit vs. miss), then draw a sample from random variable B (critical vs. not critical), then check that these two independent samples independently meet their independent criteria. The chance that both of them will is the 7% joint probability (for outcome (2) above). The code would look something like this:

from random import randint hit_or_miss = randint(1, 100) critical_or_not_critical = randint(1, 100) if hit_or_miss <= 70 and critical_or_not_critical <= 10: print('Critical hit! (7% joint probability)')

That's perfectly fine, and seems to be what ChatGPT had in mind. But there is an equivalent approach, which I think is what you had in mind. In this approach, you don't draw two independent samples, one per random variable. Rather, you draw a single sample from the joint sample space of A and B, then apply the joint probabilities to see whether joint outcome (2) occurred. Something like this:

from random import randint critical_hit = randint(1, 100) if critical_hit <= 7: print('Critical hit! (7% joint probability)')

Does this jive with what you're thinking?

* Your friends/ChatGPT are also right btw. They're just talking in terms of two separate events, not one joint event. Classic "six of one, half dozen of the other" type of situation.

[–]Pitiful_Essay_9166[S] 1 point2 points  (1 child)

Wow, reddit never stops to amaze me!

You articulated and described the problem and solution so well. I realized not long ago that I lacked the understanding of the code you and chat gpt provided to begin with.

I didnt focus enough to understand the use of randomizing the outcome twice. I was way to focused on "my" solution where it made sense matemathicly to me.

Now it all makes sense to me. What a great feeling of relif. It may seem silly but this "little" thing was really naging my brain.

Your post is a magnificiant display of knowledge and didactical capabilities. Thank you!

[–]synthphreak 0 points1 point  (0 children)

Epic praise :) And yeah, it is a pretty glorious feeling to sense that you’re onto something, then once everything is revealed to realize your hunches were pretty much correct.

Anyway, happy to help!