In Java, Generate Random Number Excluding Given Array Of Integers
class RandNum {
public static void main(String[] args) {
System.out.println("Random: " + getRandom(33, 43, 47, 7, 11, 54, 21));
}
public static int getRandom(int... numbers){
int rand, len;
do{
rand = (int)(1+Math.random()*54);
len = numbers.length;
while(0 < len && rand != numbers[--len]);
if(0 == len && rand != numbers[0])
return rand;
}while(true);
}
}
Download
Comments
Post a Comment