Code covered by the BSD License  

Highlights from
Generation of Random Variates

image thumbnail

Generation of Random Variates

by

 

generates random variates from over 870 univariate distributions

wak5_cdf(xv,p_value);
% wak5_cdf.m - Wakeby 5-Parameter Cumulative Distribution Function.
%   "Random Variate Generation in One Line of Code", L. Devroye, 1996 
%   Winter Simulation Conference Proceedings, J.M. Charnes, D.J. Morrice, 
%   D.T. Brunner and J.J. Swain eds, ACM, pp. 265-272, 
%   http://cg.scs.carleton.ca/~luc/rng.html.
%
%   created by:  J. Huntley,  10/25/06.
%
%   Vector Form of CDF.
%

function [cdf,fhold] = wak5_cdf(xv,p_value);

% Initializations.
a = p_value(1);
b = p_value(2);
c = p_value(3);
d = p_value(4);
e = p_value(5);
rand('state',0);
nsamples = size(xv,2);

% Evaluate PPF for evenly-spaced CDF values on [0,1].
xhold = rand(nsamples,1); 
fhold = e + a.*(1 - (1 - xhold).^b)./b - c.*(1 - (1 - xhold).^(-d))./d;    
fmin = min(fhold);
fmax = max(fhold);

% Sort "range" values of PPF into "domain" order.
[xsort, index] = sort(xhold);
fsort = fhold(index);

% Interpolate CDF values to uniform spacing, xi.
xi = fmin:(fmax-fmin)/(nsamples-1):fmax;
cdf = interp1(fsort,xsort,xi,'linear');

return

Contact us