CHAPTER 6

image

Random Numbers, Games, and Simulation

In this chapter, we will explain the following:

  • Random numbers
  • The difference between random and pseudorandom numbers
  • How to generate random numbers on a computer
  • How to write a program to play a guessing game
  • How to write a program to drill a user in arithmetic
  • How to write a program to play Nim
  • How to simulate the collection of bottle caps to spell a word
  • How to simulate queues in real-life situations
  • How to estimate numerical values using random numbers

6.1 Random Numbers

If you were to throw a six-sided die 100 times, each time writing down the number that shows, you would have written down ...

Get Advanced Topics in Java: Core Concepts in Data Structures 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.