Percentage chance to make action
import random
if random.randint(0,100) < 36:
do_stuff()
Just to make it more explicitly clear and more readable:
def probably(chance):
return random.random() < chance
if probably(35 / 100):
do_the_thing()
You could use random.random
:
import random
if random.random() < percentage_chance:
print('aaa')
This code returns a 1, 36% of the time
import random
import math
chance = 0.36
math.floor( random.uniform(0, 1/(1-chance)) )