Based on the links you sent, it looks like you want to generate a random number that matches some specific conditions. To do that, you will have to keep generating random numbers until you get a number that is fine for you.
Example: (with the condition you stated)
Random random = new Random(); //your random number generator
int value;
int max = 10; //max value you want to get, exclusive
int min = 1 //minimum value you want to get, inclusive
do
{
value = random.nextInt(max - min) + min; //generates a random number between min and max
}
while(value == 1 || value == 2); //will restart if value is 1 or 2, as you asked