Danny Staple 38e26f9bb9 Move this to 7 - it was closer to that example.
Some further fixes - and an experiment.
2022-11-22 22:19:25 +00:00

16 lines
426 B
Python

import random
import math
def get_standard_normal_sample():
"""Using the Marasaglia Polar method"""
while True:
u = random.uniform(-1, 1)
v = random.uniform(-1, 1)
s = u * u + v * v
if s >= 1:
continue
return u * math.sqrt(-2 * math.log(s) / s)
def get_gaussian_sample(mean, standard_deviation):
return get_standard_normal_sample() * standard_deviation + mean