Created
December 11, 2012 21:40
-
-
Save jmakeig/4262413 to your computer and use it in GitHub Desktop.
Box-Muller algorithm to transform a uniform distribution to a 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
declare namespace local="local"; | |
declare function local:random() as xs:double { | |
xdmp:random(10000) div 10000 | |
}; | |
(: http://www.exceluser.com/explore/statsnormal.htm :) | |
declare function local:box-muller() as xs:double { | |
math:sqrt(-2 * math:log(local:random())) * | |
math:sin(2 * math:pi() * local:random()) | |
}; | |
for $i in (1 to 10000) | |
return $i || "	" || local:box-muller() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment