Skip to content

Instantly share code, notes, and snippets.

@jmakeig
Created December 11, 2012 21:40
Show Gist options
  • Save jmakeig/4262413 to your computer and use it in GitHub Desktop.
Save jmakeig/4262413 to your computer and use it in GitHub Desktop.
Box-Muller algorithm to transform a uniform distribution to a normal distribution.
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