Last active
May 25, 2020 20:58
-
-
Save kurasaiteja/7430805ed4582bd148609987b40115ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def perform_bernoulli_trials(n, p): | |
#Perform n Bernoulli trials with success probability p and return number of successes. | |
# Initialize number of successes: n_success | |
n_success = 0 | |
# Perform trials | |
for i in range(n): | |
# Choose random number between zero and one: random_number | |
random_number = np.random.random() | |
# If less than p, it's a success so add one to n_success | |
if random_number<p: | |
n_success+=1 | |
return n_success |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment