I need to select one possible output based on probabilities. lets say I have
p[1]=20%
p[2]=40%
p[3]=15%
p[4]=25%
the size of p[] is a variable (in this case 4) and I know that together they sum to 100%. how to select one element from p in accordance to it's probability?