Skip to content

Instantly share code, notes, and snippets.

@vashu1
Created April 25, 2021 21:05
Show Gist options
  • Save vashu1/45f6f4705121279f1cb6bd51b348c887 to your computer and use it in GitHub Desktop.
Save vashu1/45f6f4705121279f1cb6bd51b348c887 to your computer and use it in GitHub Desktop.
import random
import math
random.seed(1) # to make reproducible results
def rand(): # +/- 10
return (random.random() - 0.5) * 20
def avg(lst):
return sum(lst) / len(lst)
def round_rand(val):
frac, i = math.modf(val)
if 0.4 < abs(frac) < 0.6:
i += random.random() - 0.5
return round(i + frac)
DAYS = 365 * 6 * 10 * 1
ANOMALY = 0.1
def run():
t = [round_rand(rand() + ANOMALY) for _ in range(DAYS)]
res = avg(t)
print(round(res, 1), res)
for _ in range(10):
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment