Gregory Lypny <[EMAIL PROTECTED]> on Mon, 1 Oct 2001
12:08:57 -0400 queried

> Hi,
>
>      I'm wondering whether anyone has a function or script
to draw from a
> Normal distribution with mean zero and variance one ---
N(0,1) --- that
> they might be willing to share.
>
>      Regards,
>
>           Greg
>
>
>
>
____________________________________________________________
> Gregory Lypny
> Associate Professor
> John Molson School of Business
> Concordia University
> Montreal, Canada


Yep. Here's one.

function randNorm01 n,prec
  -- n is the number of random variables, prec is the number
of decimal places per answer.
  set numberformat to char 1 to 2+prec of "0.000000000000"
  put (1+n) div 2 into k
  put 10^prec into trange
  repeat with i = 1 to k
    put 2*random(trange)/trange - 1 into x1
    put 2*random(trange)/trange - 1 into x2
    put x1*x1+x2*x2 into w
    try
      put sqrt((-2*ln(w))/w) into w
      put x1*w into line(2*i-1) of y
      put x2*w into line(2*i) of y
    catch errnum
      subtract 1 from i
    end try
  end repeat
  delete line n+1 of y
  return y
end randNorm01


Archives: http://www.mail-archive.com/[email protected]/
Info: http://www.xworlds.com/metacard/mailinglist.htm
Please send bug reports to <[EMAIL PROTECTED]>, not this list.

Reply via email to