A test for a certain rare disease is assumed to be correct 95% of the time: if a person has disease, the test results are positive with probability 0.95, and if the person does not have the disease, the test results are negative with probability 0.95. A random person drawn from a certain population has probability 0.001 of having the disease.
Given that the person just tested positive, what is the probability of having the disease?
Just pseudocode would be great
Try something like this:
You can easily simulate the first three steps and then calculate the fourth, though like any simulation you should not expect the calculation to be particularly accurate, especially of a very rare disease.