### Generating Random Numbers

The `java.util.Random` class provides a pseudorandom number generator that is more flexible than the one in the `Math` class. Actually, the random number generator in the `Math` class just uses one of the methods in the `Random` class to produce its results. Because the methods in the `Random` class are not `static,` you must create an instance of `Random` to use it. You can do this with the no-argument constructor or the one that accepts a seed:

public Random() public Random(long seed)

Note

"Random" numbers generated by a mathematical algorithm are not truly random, but are instead well-distributed values taken from a sequence that is defined by the algorithm. This distinction is why `java.util.Random` is described as a pseudorandom ...

Get *Special Edition Using Java 2 Standard Edition* now with O’Reilly online learning.

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