As soon as you impose certain rules to the numbers being generated (eg they cannot be duplicates), you can't really consider them random anymore.
You could consider adding oneNumber to twoNumber (or any other operation where oneNumber is used in the calculation of twoNumber), that way they'll never be equal. Although this again imposes the fact that twoNumber will always be higher then oneNumber, so could again be seen as a breach in the 'Random' concept.
oneNumber = 1 + (int) (Math.random() * randOne);
twoNumber = 1 + oneNumber + (int) (Math.random() * randTwo);
For your requirement where you want to generate the first number between 1-4 and second number between 1-5 without duplicates you could use following approach:
// Create a list containing numbers 1 till 5
List<Integer> numbers = new ArrayList<Integer>();
for(int i = 1; i < 6; i++) {
numbers.add(i);
}
Random random = new Random();
// Randomly get the index of your first number, this will be a number
// between 1 and 4
int firstIndex = random.nextInt(4);
int number1 = numbers.get(firstIndex);
// Remove that number from the list, your list now becomes size 4, and no
// longer contains the first number you picked.
numbers.remove(firstIndex);
// Randomly get the index of your second number, this will be a number
// between 1 and 5 without the number picked earlier.
int secondIndex = random.nextInt(4);
int number2 = numbers.get(secondIndex);
System.out.println(number1);
System.out.println(number2);
Or perhaps cleaner and faster:
// Create a list containing numbers 1 till 5 -> might want to extract this
// from the method so you don't have to rebuild the array over and over
// again each call...
List<Integer> numbers = new ArrayList<Integer>();
for(int i = 1; i < 6; i++) {
numbers.add(i);
}
// Shuffle the array randomly
Collections.shuffle(numbers);
// Get the first 2 numbers from the array
int number1 = numbers.get(0);
int number2 = numbers.get(1);
// If number1 equals 5, swap number1 and number2 as you want number1 to be
// 1-4 and number2 to be 1-5
if(number1 == 5) {
number1 = number2;
number2 = 5;
}
System.out.println(number1);
System.out.println(number2);