|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Random number generator that returns numbers from
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








