Sampling from discrete probability distribution from first principles
问题 I have a set S={a1,a2,a3,a4,a5,......,an}. The probability with which each of the element is selected is {p1,p2,p3,p4,p5,...,pn} respectively (where ofcourse p1+p2+p3+p4+p5+....+pn=1}. I want to simulate an experiment which does that. However I wish to do that without any libraries (i.e from first principles) I'm using the following method: 1) I map the elements on the real number line as follows X(a1)=1; X(a2)=2; X(a3)=3; X(a4)=4; X(a5)=5;....,X(an)=n 2) Then I calculate the cumulative