21.5 Random Numbers: Random, ThreadLocalRandom, and SecureRandom
The Math class provides a simple method for random numbers: random() . Internally, however, this method based on a different class that you can also use directly, thus enabling you to ask for more than just random numbers between 0 and 1.
The usual random numbers of Java are actually pseudo-random numbers because they are generated by a mathematical algorithm. Good “random values” are repeated only after exceedingly long sequences, have no obvious context, and are generated quickly. Perfect random numbers would never be predictable: The probability for each number would always be the same—regardless of the preceding values—and the sequences would never be repeated.
21.5.1 The ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access