Probability Calculator unit test issue/question

It is to do with random. You can look at another post of mine on a similar issue for more information. In this particular situation, the unit test sets the seed of the random number generator for every test so that it will generate the same sequence of random numbers every time the tests are run, which generates the same probability every time, thus simplifying the test construction. You can seed your generator too, and cause the same behavior.

The probability changes from run to run (unless you seed the generator) because you are simulating the situation with a small number of trials, which will generate a final probability (pseudo-?) randomly distributed around the actual probability, which can be worked out analytically. If you let your program run for many iterations, it should converge on the analytical probability.

3 Likes