---Robert Cyr wrote:
> More general than the ! gamma J function, we can use:
> gma=: 4 : 0
>     'a b'=.x
>      (((y%b)^<:a)*^-y%b)%b*!<:a
> )
> where a is the shape parameter and b is the scale parameter.
>
> I am looking for a Gamma distribution randon number generator in J.

>From the statdist.ijs script ( open 'statdist' )

NB. =========================================================
NB. gammarand
NB. random numbers in a gamma distribution
NB. y has 2 elements p,n
NB.   0 = power parameter
NB.   1 = number of trials
NB.
NB. if p=1 this is the exponential distribution
gammarand=: 3 : 0
'p n'=. y
r=. n#0
k=. p-i=. <.p
if. k do.
  r=. betarand k,(-.k),n
  r=. r * -^.rand01 n
end.
if. i do.
  r-^.*/rand01 i,n
end.
)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to