Skip to content

Commit 1a19ddb

Browse files
authored
Create Bernoulli Sample.py
1 parent 531bcbc commit 1a19ddb

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Write a function to get a sample from a Bernoulli trial.
2+
3+
import random
4+
5+
def bernoulli_sample(p):
6+
x=random.random()
7+
if x<=p:
8+
return 1
9+
else:
10+
return 0

0 commit comments

Comments
 (0)