Created
March 16, 2016 17:35
-
-
Save inoryy/ef43549d91bdfb757393 to your computer and use it in GitHub Desktop.
Normal Distribution via Box–Muller transform
This file contains hidden or 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
from random import random | |
from math import log, cos, sin, sqrt, pi | |
# Implementation of Box-Muller transform to | |
# generate two random numbers from N(mu, sigma) distribution | |
def pnorm(mu = 0, sigma = 1): | |
r = sqrt(-2*log(random())) | |
a = 2*pi*random() | |
return sigma*r*cos(a) + mu, sigma*r*sin(a) + mu |
Author
inoryy
commented
Mar 16, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment