Code covered by the BSD License  

Highlights from
Generation of Random Variates

image thumbnail

Generation of Random Variates

by

James Huntley (view profile)

 

generates random variates from over 870 univariate distributions

lsuccess_cdf(n, p, nn)
% lsuccess_cdf.m - evaluates Length of Longest Success Run Cumulative Distribution.
%   See "Simple Expressions for Success Run Distributions in Bernoulli Trials",
%   M. Muselli, Genoa.
%
%  Created by Jim Huntley,  01/02/08
%

function [cdf] = lsuccess_cdf(n, p, nn)

q = 1 - p;
sumy = 0;
ymin = fix(nn/n);

for y = ymin:nn 
    coef = p^(nn-y) * q^y;
    summ = 0;
    mmax = fix((nn-y)/n)+1;
    for mm = 1:mmax
        m = mm - 1;
        summ = summ + (-1)^m * binomial_coef(y+1,m) * binomial_coef(nn-m*n,y);
    end
    sumy = sumy + coef * summ;
end

cdf = sumy;

return

Contact us