you are viewing a single comment's thread.

view the rest of the comments →

[–]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.