Chapter 23. Take a Chance—Randomness
One of the most fun things about games is that you never know what will happen. Games are unpredictable. They’re random. It’s this randomness that makes them interesting.
As we have already seen, computers can simulate random behavior. In our number-guessing program (in chapter 1), we used the random module to generate a random integer, which the user had to guess. You also used random to pick words for the silly sentence program in the “Try it out” section in chapter 22.
Computers can also simulate the random behavior of rolling dice or shuffling a deck of cards. This makes it possible to create computer games with cards or dice (or other randomly behaving objects). For example, almost everyone has tried ...
Get Hello World! now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.