[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math

Search:


View post   

>> No.8430363 [View]
File: 76 KB, 651x378, Screen Shot 2016-10-22 at 22.37.06.png [View same] [iqdb] [saucenao] [google]
8430363

such a function may come in handy:
p_if(0.7, "foo", "bar")
returns "foo" 70% of the time, and else "bar".

#################


import random

def p_if(p=0.5, a=True, b=False):
P = random.uniform(0,1) <= p
return a if P else b

### the above implementations has defaults 0.5, True as first value and False as second.

Navigation
View posts[+24][+48][+96]