% Chooses a random number from x where x(i) has probability % weights(i) of being chosen. % For example, to choose an exponentially distributed random % variable, you might do: % x=0:.1:20; % w=lambda*exp(-lambda*x); % r=randnum(w,x); % % NOTE: If weights does not sum to 1, it will be normalized % so that it does. It must be positive, though. % r=randnum(weights,x); function r=randnum(weights,x); r=x(discrete_rv(weights));