Last active
February 22, 2016 21:47
-
-
Save NathanEpstein/8549fe4c53a26afd11d7 to your computer and use it in GitHub Desktop.
Box Muller transform in ruby
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
def boxMuller() | |
u1, u2 = rand, rand | |
z1 = Math.sqrt(- 2 * Math.log(u1)) * Math.cos(2 * u2 * Math::PI) | |
z2 = Math.sqrt(- 2 * Math.log(u1)) * Math.sin(2 * u2 * Math::PI) | |
[z1,z2] | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment