I'm really used to writing if statements for two different events, which could be best outlined by the following pseudocode:
double random = Math.random();
if(random<0.5) event A;
else event B;
But when there's more than 2 different events (let's say 4 in this instance) with different probabilities, the only thing I've found is the following, but it seems way too verbose for the simple thing I'm trying to achieve, there has to be a much simpler way to do this, right?
double random = Math.random();
if(random<0.3) event A;
else if(random>=0.3 && random<0.5) event B;
else if (random>=0.5 && random<0.8) event C;
else event D;
Clearly there's a better algorithm to do this?