created: 07/31/07; revised 10/22/08
CHAPTER 20 — The Random Class
Programs frequently need random numbers.
A card game uses random numbers to create a shuffled deck of cards.
A dice game uses random numbers to simulate a throw.
Many activities in the real world (such as traffic on a highway system)
appear to be random, and a program that models them uses random numbers.
This chapter discusses the Random class that comes with Java.
The chapter discusses:
- Random numbers
- Random number generators
- Uniform and non-uniform distributions
- The
Randomclass - Seeds for
Random() - Tossing dice
- Picking passwords
Random numbers, probability, and statistics are important for testing, for modeling the world, and for general understanding of the universe. Computer science degree programs usually require a course in these subjects.
QUESTION 1:
What number is most likely outcome for a throw of a fair die?