Subject: Re: [xsl] Random number generator that returns numbers from a normal probability distribution and with a specified standard deviation? From: "Mary Holstege holstege@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Tue, 2 Jun 2020 13:48:03 -0000 |
I have an XQuery function that does it. It depends on an underlying function (here rand:uniform) to give uniform numbers in [0,1].B Most "random" functions will give you uniformly distributed random numbers; if your platform doesn't have one, you'll have to concoct your own pseudo-random function This is the polar variant of the Box-Muller algorithm (: : normal() : Return random normally distributed data. : : $mean: Mean of range of values : $std: Standard deviation of range of values :) declare function rand:normal( $mean as xs:double, $std as xs:double ) as xs:double { $mean + rand:gauss() * $std }; (: : gauss() : Return random normally distributed data between 0 and 1 : A service function used by normal() :) declare %private function rand:gauss() as xs:double { let $u as xs:double := 2 * rand:uniform(0,1) - 1 let $v as xs:double := 2 * rand:uniform(0,1) - 1 let $r := $u * $u + $v * $v return ( if ($r = 0 or $r >= 1) then rand:gauss() else ( let $c as xs:double := math:sqrt(-2 * math:log($r) div $r) return $u * $c ) ) }; On 5/31/20 10:37 AM, Roger L Costello costello@xxxxxxxxx wrote: > Hi Folks, > > I need a random number generator that returns numbers from a normal probability distribution, centered around zero, and with standard deviation that can be specified. Has anyone created such a thing? > > I am using XSLT/XPath 2.0 > > /Roger
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] XSL-List Guidelines, B Tommie Usdin btusd | Thread | Re: [xsl] Random number generator t, Roger L Costello cos |
[xsl] XSL-List Guidelines, B Tommie Usdin btusd | Date | [xsl] creating multi-level TOC from, Charlie0 charlieo0@x |
Month |