octave:2> v=rand(1,5) v = 0.47487 0.77408 0.15505 0.94272 0.84118 octave:3> v=v/sum(v) v = 0.148961 0.242817 0.048638 0.295719 0.263866 octave:4> rand u=rand u = 0.71140 octave:6> cumsum(v) ans = 0.14896 0.39178 0.44042 0.73613 1.00000 octave:7> u u=rand u = 0.60588 octave:9> u=rand u = 0.34630 octave:10> u find(u min(find(u testsimula octave:14> testsimula octave:15> quit