Skip to content

Instantly share code, notes, and snippets.

@NathanEpstein
Last active February 22, 2016 21:47
Show Gist options
  • Save NathanEpstein/8549fe4c53a26afd11d7 to your computer and use it in GitHub Desktop.
Save NathanEpstein/8549fe4c53a26afd11d7 to your computer and use it in GitHub Desktop.
Box Muller transform in ruby
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