research/casper/distributions.py

38 lines
604 B
Python
Raw Normal View History

2015-07-19 15:01:20 -04:00
import random, sys
def normal_distribution(mean, standev):
def f():
2015-08-27 09:38:48 -04:00
return int(random.normalvariate(mean, standev))
2015-07-19 15:01:20 -04:00
return f
def exponential_distribution(mean):
def f():
total = 0
while 1:
total += 1
2015-08-27 09:38:48 -04:00
if not random.randrange(32):
2015-07-19 15:01:20 -04:00
break
2015-08-27 09:38:48 -04:00
return int(total * 0.03125 * mean)
2015-07-19 15:01:20 -04: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