Simple problem:
JavaScript
x
6
1
percentage_chance = 0.36
2
3
if some_function(percentage_chance):
4
# action here has 36% chance to execute
5
pass
6
How can I write some_function
, or an expression involving percentage_chance
, in order to solve this problem?
Advertisement
Answer
You could use random.random
:
JavaScript
1
5
1
import random
2
3
if random.random() < percentage_chance:
4
print('aaa')
5