[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Random number generator that returns numbers from

Subject: Re: 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
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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.