The random() method of the Math class provides a number generated pseudo-randomly.
Follows a pre-programmed algorithm based upon a seed (root) number which is within Java. With this Java stays platform independent (does not use resource from outside Java like system clock) but the number is not true random. However, for normal purposes, pseudo-random number are fine.
The generator is within the Math class.
It generates a double number in the [0, 1) interval.
EXAMPLE FOR RANDOM NUMBERS:
The Random class is a random number generator which generates a stream upon declaration, containing pseudo-random series of numbers. The numbers follow a well-designed pattern to be look like random, uses a 48-bit seed, and generates maximum 32-bit numbers.
The reason for using a well-defined mathematical pattern is, it is not needed to use an independent and always changing seed (root number) coming from outside the Java (e.g. system time). With this, it is possible to re-generate the same series of numbers and recreate the examined environment in case the second Random uses the same seed and declared in the same method.
By using its methods, it is possible to export the whole stream from double, float, long, int and byte types.
Asking numbers one-by-one, use methods like nextByte(), nextFloat().
In order to set the seed, use the setSeed(long seed) method.
EXAMPLE FOR PSEUDO-RANDOM NUMBERS:
The SecurityRandom class provides a cryptographically strong random number generator. It generates true random numbers which means non-deterministic output.
EXAMPLE FOR TRUE RANDOM NUMBERS 1:
EXAMPLE FOR TRUE RANDOM NUMBERS 2:
Other methods are below.