How to Generate Random Number in Java

This is the easiest way to generate a random number (in a given range) in Java. This can be helpful especially if you want to randomize an animation in Android. It might be useful in Java too (if you need a random number out of a range).

int min = 65;
int max = 80;
Random r = new Random();
int i1 = r.nextInt(max - min + 1) + min;

Hope this little snippet helps!

Leave a Reply