Code covered by the BSD License

# Generation of Random Variates

### James Huntley (view profile)

generates random variates from over 870 univariate distributions

tdiff_cdf(x, nu)
```% tdiff_cdf.m - evaluates a T-Difference Cumulative Distribution.
%   See "Continuous Univariate Distributions", Vol.2, Johnson, Kotz,
%   & Balakrishnan, J. Wiley, 1995, p.411.
%
%   Vector Form of CDF!!!
%
%  Created by Jim Huntley,  01/06/10
%

function [cdf] = tdiff_cdf(x, nu)

%persistent coef ymin ny imax tol trace

%Initializations.
%if(isempty(coef))
coef = 2 * exp(gammaln(0.5*(nu+1)) - nu*log(2) - 0.5*log(pi) - 2*gammaln(0.5*nu));
ymin = 1e-6;
ny = 1000;
imax = 100;
tol = 1e-8;
trace = [];
%end

for jx = 1:size(x,2)
ymax = 0.25 * (x(jx))^2 / nu;
dy = (ymax-ymin) / (ny-1);
y = ymin:dy:ymax;
sum1 = 0;
for ii = 0:imax
term1 = exp(gammaln(ii+0.5) + gammaln(nu+ii+0.5) - ...
gammaln(ii+1) - gammaln(0.5*nu+ii+1));
sum1 = sum1 + term1 * int1;
end
cdf(jx) = coef * sum1;
end

return

function [kern] = kernfn(y, nu, ii)

kern = y.^(ii-0.5) ./ (1+y).^(0.5+nu+ii);

return

```