Last active
June 3, 2019 12:51
-
-
Save trevphil/1b885ac68f70b24ce44e52d2cf81565b to your computer and use it in GitHub Desktop.
Sampling from normal distribution
This file contains 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
private func sampleNormalDist(withMean mean: Double, std: Double) -> Double { | |
precondition(std > 0) | |
let first = Double(rng.nextUniform()) | |
let second = Double(rng.nextUniform()) | |
let zScore = sqrt(-2 * log(first)) * cos(2 * Double.pi * second) | |
return zScore * std + mean | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment