Code covered by the BSD License

# Generation of Random Variates

### James Huntley (view profile)

generates random variates from over 870 univariate distributions

gaus1_ppf(xv, p_value);
```% gaus1_ppf.m - numerically estimate single-point Gaussian (normal) Point Percent Function.
%
% created by:  J. Huntley,  09/30/04.
%
% Calls:    'gaus_pdf.m'
%
% Called by:    'gandh_cdf.m'
%

function [ppf,xv] = gaus1_ppf(xv, p_value);

m = p_value(1);
sigma = p_value(2);
ftol = 1e-10;  					% convergence criterion.
itmax = 100;  					% iteration limit.

% Sample the distribution's PPF by using MFP to numerically find the zeros of
% the function: PPF - (URD=xv).
x0 = -1000;
xn = 1000;
n = 0;
f0 = gaus_cdf(x0,m,sigma) - xv;
xi = xn;
fi = gaus_cdf(xn,m,sigma) - xv;
while (abs(fi) > ftol & n <= itmax)
xn = xi;
fn = fi;
xi = (x0*fn - xn*f0) / (fn - f0);
fi = gaus_cdf(xi,m,sigma) - xv;
if(abs(fi) <= ftol)
break
end
n = n + 1;
if(n > itmax)
WARNING = 'n > itmax, gauss1_ppf'
Distribution = distrib{d_indx}
break
end
if((fi * fn) > 0)
f0 = 0.5 * f0;
else
x0 = xn;
f0 = fn;
end
end % while Loop.

ppf = xi;

return```