function [state] = sample_multi(phi) dim = length(phi); prob = rand; test = 0; for i=1:dim test = test + phi(i); if(test >= prob) state = i; return; end end