Created
February 12, 2019 17:35
-
-
Save neila/f71fd6ce0b372cda076f643e29efe8f8 to your computer and use it in GitHub Desktop.
CS110 5.1 Preclass
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
import random | |
import numpy as np | |
for i in range(100): | |
list = [int(100*random.random()) for i in range(100)] | |
sigma = random.randint(1,49) | |
sigma | |
low = np.percentile(list, 50-sigma) | |
high = np.percentile(list, 50+sigma) | |
samp = float("Inf") | |
retry = 0 | |
while samp < low or high < samp: | |
samp = random.choice(list) | |
retry += 1 | |
if retry == 3: | |
print("fail!") | |
break | |
print(samp, "was in between", 50-sigma, "and", 50+sigma, "percentile") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment