The random class contains two construction methods, which are described in turn:
1. Public Random ()
The construction method uses a number that corresponds to the relative time of the current system time as the seed number, and then constructs the random object using this seed number.
2. Public Random (Long Seed)
The construction method can be created by setting a seed number.
Example code:
Random r = new Random ();
Random r1 = new Random (10);
Random r2 = new random (10);
It is emphasized that the number of seeds is only the origin number of the random algorithm, regardless of the interval of the generated random numbers. Random objects of the same seed number are identical in number. So no matter how many random numbers you need to generate in your project, you can use just one random object, namely:
R1.nextint ();
R2.nextint ();
The random number returned at the first or (same time) call is the same, but
for (int i = 0;i < 2;i++) {
System.out.println (R1.nextint ());
}
Generates two different random numbers
Java Programming Ideas Random (47)