Check the code below. isValidNumber(...) method will check if the random number is previously selected or not and will return true if it is not selected before. You can fill that method yoursef.
for (int index = 0; index < lotteryNumbers.length; index = index + 1)
{
int tmp = random.nextInt(49);
while (!isValidNumber(tmp)) {
tmp = random.nextInt(49);
}
lotteryNumbers[index] = tmp;
}
private boolean isValidNumber(int[] lotteryNumbers, int currentIndex, int currentNumber) {
...
}