function tsamps = disc_inv_tranf(p,n) % DISC_INV_TRANF - generate discrete random variables using the discrete inverse transformation % % 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. % %----- % the number of discrete random variables nDisc = length(p); % for the bin "boundaries" for this set of mass distributions. pcs = [ 0, cumsum(p(:).') ]; Us = rand(1,n); [N,tsamps] = histc( Us, pcs );