research/old_casper_poc3/distributions.py

38 lines
604 B
Python
Raw Normal View History

2015-07-19 19:01:20 +00:00
import random, sys
def normal_distribution(mean, standev):
def f():
2015-08-27 13:38:48 +00:00
return int(random.normalvariate(mean, standev))
2015-07-19 19:01:20 +00:00
return f
def exponential_distribution(mean):
def f():
total = 0
while 1:
total += 1
2015-08-27 13:38:48 +00:00
if not random.randrange(32):
2015-07-19 19:01:20 +00:00
break
2015-08-27 13:38:48 +00:00
return int(total * 0.03125 * mean)
2015-07-19 19:01:20 +00:00
return f
def convolve(*args):
def f():
total = 0
for arg in args:
total += arg()
return total
return f
def transform(dist, xformer):
def f():
return xformer(dist())
return f