The Random class
java.util.Randomhttp://docs.oracle.com/javase/7/docs/api/java/util/Random.html
Importing java.util.Random
You will need the following imports statement at the top of your code file:import java.util.Random;
Generate any random number
Random r = new Random();r.nextInt();
generates a random number in the int range (-2,147,483,648 to 2,147,484,647).
r.nextInt(max);
Generate a random within a maximum range
Random r = new Random();r.nextInt(max);
generates a random number in the positive int range, inclusive of 0 but exclusive of max.
eg.
r.nextInt(500);
r.nextInt(500);
generates a number from 0 to 499. If you want to include 500 in the range, add + 1.
r.nextInt(500 + 1);
r.nextInt(500 + 1);
Generate a random within a minimum and maximum range
Random r = new Random();r.nextInt(max - min) + min;
generates a random number in the positive int range, inclusive of min but exclusive of (max - min) and then adds the minimum to correct the range.
eg.
r.nextInt(500 - 300) + 300;
Generates a number from 0 to 299. You can then add your minimum so now the number has the range of 299 to 599. Remember, the actual number will be exclusive of the max so if you want to include the max add + 1.
r.nextInt((500 - 300) + 1) + 300;
Here's a cat.

Here's a cat.











