Hi,
I need to write a piece of code that check if event has occurred on the basis of a given probability. For example, given 0.0025 is probability for event A to occur. How can I simulate it in C/C++ code.
Thanks,
Munir
1 reply to this topic
#1
Posted 08 November 2010 - 11:44 AM
|
|
|
#2
Posted 08 November 2010 - 12:19 PM
You simulate that by using geometric probability: if desired probability is a/b (e.g. 0.0025 = 1/400), then event occurs when discrete variable X uniformly distributed over set {0, 1, ..., b - 1} is less than a.
In your example, event occurs if (rand() % 400) == 0.
In your example, event occurs if (rand() % 400) == 0.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









