Monday, 22 August 2011

Generating Poisson distributed random integers

MATLAB code to generate N Poisson distributed random integers with rate parameter lambda:
out = [];
for ii = 1 : N
    L = exp(-lambda);
    k = 0;
    p = 1;
    while (p > L)
        k = k + 1;
        p = p*rand;
    end
    out(end+1) = k-1;
end

No comments:

Post a Comment