This content has been marked as final. Show 4 replies
You can use java.util.Random;
Random rand = new Random();
int random = 20 + rand.nextInt(11);
if you know how to generate a random number between 0 and 1. (there is a function in the Math API i think) you can then generate this number, multiply it by your range then add the minimum value to it.
This is the method i usually use, because it is easy to see what is happening.
double x = java.lang.Math.random(); // generates a number between 0 and 1. // for your example the range is 30-20 = 10 so x = x*10; // the number is now between 0 and 10. // you want it between 20 and 30, so add 20! x = x + 20;