research/casper/distributions.py

39 lines
665 B
Python
Raw Normal View History

2015-07-19 19:01:20 +00:00
import random, sys
def normal_distribution(mean, standev):
def f():
total = sum([random.choice([1, -1]) for i in range(529)])
return int(total * (standev / 23.0) + mean)
return f
def exponential_distribution(mean):
def f():
total = 0
while 1:
total += 1
if not random.randrange(500):
break
return int(total * 0.002 * mean)
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