Let’s use the Math.random method to generate a random number in a given range: public int getRandomNumber(int min, int max) { return (int) ((Math.random() * (max – min)) + min); } Why does that work? Well, let’s look at what happens when Math.random returns 0.0, it’s the lowest possible output: 0.0 * (max – min) …
Continue reading “How to get random number in a range in Java”