int startingNum = 1; int endNum =10; // returns a random int in range 1-10 int randInteger = (int)(Math.random() * (endNum - startingNum + 1)) + startingNum; return randInteger; } code example
Example: java random numbers in specific range
import java.util.Random;
Random rand = new Random();
int random_integer = rand.nextInt(upperbound-lowerbound) + lowerbound;