function tsamps = rubinstein_beta(alpha,beta,n) % RUBINSTEIN_BETA - generate random variables according to a beta distribution % according to the method of Rubinstein % % Input: % n: we generate a [1,n] array of random variables. % % Written by: % -- % John L. Weatherwax 2008-02-20 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- indx=1; tsamps = zeros(1,n); while( indx<=n ) y1 = rand(1,1)^(1/alpha); y2 = rand(1,1)^(1/beta); if( y1+y2<=1 ) tsamps(indx)=y1/(y1+y2); indx=indx+1; end end