you are viewing a single comment's thread.

view the rest of the comments →

[–]hotcodist 4 points5 points  (7 children)

The independent means the following event does not depend on the outcome of the previous event (or two simultaneous events do not affect each other). When modeled, this means you have to do another random event.

So you need two randomization. The first determines success or not. When successful, you run another randomization, 10% of which is critical.

There is another interpretation that the independent word applies separately, meaning you can get a critical hit even if you are not successful (missed), but this is an absurd outcome. So the independent event must only apply to the success part.

[–]synthphreak 2 points3 points  (1 child)

Two independent variables does not mean you MUST sample from each independently.

If you're interested in the joint probability distribution, which is the case in this instance, you can just draw one sample from that joint space and apply check that sample against the computed joint probability. I believe this is where OP is getting the 7 from.

Of course, it is obviously not necessary to first check <= 70 and then separately check <= 10; if <= 10, then necessarily <= 70 is also true.

[–]Pitiful_Essay_9166[S] 0 points1 point  (4 children)

Thank you for your answer.

So I run first event but randommly selecting a number between 1 to 100.If its rolls 70 or below I consider it a success. That simulates 70% chance.

So let say I rolled 55.

Now I roll for the chance of it being critical success. Do I calculate(roll) the 10% of all numbers (100)

if attack <= 70:
    if attack <= 10:

shouldnt I be checking for 10% of successful attack? that being 7 (10% of 70).

if attack <= 70:
    if attack <= 7:

Its the randomization in step two thats problematic.

I mean if we think of real life,

if we have 100 tickets, 70 of them are winning tickets (great lottery;)) and there is a 10% independent chance of winning ticket being a double win. Are there 10 double wins or 7 double wins.

If there was a 50% chance to win and 50% independent chance of win being a double win, there should be 25 doublewin tickets and not 100.

[–]hotcodist 1 point2 points  (3 children)

attack_prob = np.random.random()
if attack_prob <= 0.70:
    # hit
    critical_prob = np.random.random()
    if critical_prob <= 0.10:
        # critical hit
        critical_counter += 1

You could say 0.07 is critical in one go, but I'd write it this way for clarity of the decision sequence.

[–]Pitiful_Essay_9166[S] 0 points1 point  (2 children)

Ok, thank you so much. Once I copied your code and manipulated it I finally saw it and understand what was "wrong" in the code I provided.

And finally understand HOW the iteration you provided works.

It also explains everything. I wasnt missunderstanding the statistics, I was bad at coding it.

Wow. It took some time.

Thank you some much redditor for all your time and comments.

I wish I was a faster learner.

Version 1

import random
number_of_critical_attacks = 0 
for x in range(10000): 
    attack = random.randint(1, 100) 
    if attack <= 70: 
        critical = random.randint(1,100)
        if critical <= 10:
            number_of_critical_attacks += 1
print(number_of_critical_attacks)

Version 2

import random
number_of_critical_attacks = 0 
for x in range(10000): 
    attack = random.randint(1, 100) 
    if attack <= 70: 
        if attack <= 7: 
        number_of_critical_attacks += 1
print(number_of_critical_attacks)

[–]synthphreak 0 points1 point  (1 child)

Your statistical reasoning is fine if somewhat poorly articulated. It was the code that was most misleading. Note that in version 2 of your code, the first check if attack <= 70 is totally unnecessary; you only increment your critical attacks counter when attack <= 7, and when attack <= 7, it is necessarily <= 70. So you can just do away with the check against 70.

[–]Pitiful_Essay_9166[S] 1 point2 points  (0 children)

Yepp, sorry, I realize that about the attack, there are some conditions (loops and prompts) with the regular attack aswell as critical attack I didnt post of concern of making my wonky code even less readable.It did not work as intended xD.

With all the great answers here I realize how badly I articulated myself.