Skip to content

Instantly share code, notes, and snippets.

@neila
Created February 12, 2019 17:35
Show Gist options
  • Save neila/f71fd6ce0b372cda076f643e29efe8f8 to your computer and use it in GitHub Desktop.
Save neila/f71fd6ce0b372cda076f643e29efe8f8 to your computer and use it in GitHub Desktop.
CS110 5.1 Preclass
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