Mik*_*lla 32 python scientific-computing
是否有一个Python的标准函数,它根据从0到1的随机数的输入概率性地输出True或False?
我的意思是:
def decision(probability):
...code goes here...
return ...True or False...
Run Code Online (Sandbox Code Playgroud)
上面的例子,如果给出一个输入,比方说,0.7将以70%的概率返回True,而以30%的概率返回false
NPE*_*NPE 70
import random
def decision(probability):
return random.random() < probability
Run Code Online (Sandbox Code Playgroud)