6.5 Randomness
Many programming languages have functions that return pseudo-random numbers. The prefix “pseudo” is there because they are not genuinely random numbers but, nevertheless, they do well on statistical measurements of how well-distributed the results are. number$random
Given four possible events, E0, E1, E2, and E3, with associated probabilities p0, p1, p2, and p3, how might we use random numbers to simulate these events happening with
The probabilities add up to 1.0, as expected. random programming language$Python
In Python, the random() function returns a random real number r such that 0.0 ≤ r < 1.0. We determine that one of the E0, E1, E2, and E3, events occurred based on the value of r computed. random()`function-name random`module-name
If you are not using Python, use whatever similar function is available in your programming language and environment.
The general scheme is to run the following...