Created
April 25, 2021 21:05
-
-
Save vashu1/45f6f4705121279f1cb6bd51b348c887 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
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