Percentage chance to make action

前端 未结 3 1707
长情又很酷
长情又很酷 2020-12-13 14:24

Simple problem: percentage_chance = 0.36

if :
   #action here has 36% chance to execute
   pass

How can i solve thi

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-13 15:05

    You could use random.random:

    >>> import random
    >>> if random.random() < percentage_chance:
        print('aaa')
    

提交回复
热议问题