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! Computer Programming for Kids and Other Beginners now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.