Jump to content

Probability for an event

- - - - -

  • Please log in to reply
1 reply to this topic

#1
mnirahd

mnirahd

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 330 posts
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

#2
zoranh

zoranh

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 207 posts
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.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users