If different events have a specified probability of happening, can you first check if the first event happens, then next, then next ...?

28 Views Asked by At

To be more precise: I have an event that happens. The outcome of that event is divided into several probabilistic events. For example: There's a 1/128 chance that A happens, a 1/64 chance that B happens, and otherwise C happens.

When evaluating this event in a computer program, is it correct to:

  1. Roll a random number between [0,1) to check if it's < 1/128 -> if so A happens
  2. If not we roll again between [0,1) to check if it's < 1/64 -> if so B happens
  3. If not C happens

I feel like this is incorrect because if we know A happens, the odds of B happening increase, thus steps 2 and 3 are then not valid anymore.

Could anyone verify this and suggest a better algorithm of evaluating such events? Thanks!

1

There are 1 best solutions below

0
On BEST ANSWER

Correcting a typo from a prior comment:

Your method does not work because your events $A,B$ would overlap (if the random number is less than $\frac 1{128}$ then both $A,B$ occur).

A variant which does work:

(assuming a random number, $\alpha$, uniform on $[0,1]$ has been selected)

If $\alpha$ is $≤\frac 1{128}$ then $A$.

If $\frac 1{128}< \alpha < \frac 1{128}+\frac 1{64}$ then $B$.

If $\alpha$ is $≥ \frac 1{128}+\frac 1{64}$ then $C$.