Relative probabilities using random number gen
- by CyberShot
If I have relative probabilities of events A, B, C occurring.
i.e P(A) = 0.45, P(B) = 0.35, P(C) = 0.20,
How do I do represent this using a random number generator between 0 and 1?
i.e. R = rand(0,1)
if (R < 0.45)
event A
else if(R < 0.35)
event B
else if(R < 0.20)
event C
The above works for two events A,B but I think the above is wrong for three or more since there is overlapping.
This is obviously a very simple question and the answer should be immediately evident, but I'm just too stupid to see it.