Generating a truly random number is a big topic that does not belong to this book. But for the vast majority of practical purposes, the pseudo-random number generators provided by Java are good enough, and that is what we are going to discuss in this section.
There are two primary ways to generate a random number in Java Standard Library:
- The java.lang.Math.random() method
- The java.util.Random class
There is also the java.security.SecureRandom class, which provides a cryptographically strong random number generator, but it is outside the scope of an introductory course.