Unity Artificial Intelligence Programming - Fourth Edition
by Dr. Davide Aversa, Aung Sithu Kyaw, Clifford Peters
Loaded dice
Now, let's assume that we haven't been all too honest, and our dice are loaded so that the side of the number six has a double chance of landing facing upward. Since we doubled the chance of getting six, we need to double the probability of getting six, let's say, up to roughly one third (0.34), and, as a consequence, the rest will be equally spread over the remaining five sides (0.132 each).
We can implement a loaded dice algorithm in this way: first, we generate a random value between 1 and 100. Then, we check if the random value falls between 1 and 35. If so, our algorithm returns 6; otherwise, we get a random dice value between one and five, since these values have the same probability.
So, here's our throwLoadedDice() method: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access