View Single Post
  #2 (permalink)  
Old 11-02-2007, 04:07 PM
JavaBean's Avatar
JavaBean JavaBean is offline
Moderator
 
Join Date: May 2007
Posts: 1,272
JavaBean is on a distinguished road
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.

Code:
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) { ... }
Reply With Quote