O'Reilly logo

Hello World! Second Edition: Computer Programming for Kids and Other Beginners by Warren Sande and Carter Sande

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 you 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required