I'm attempting to generate a random four digit number with no repeating digits. I have a method to generate the number and two to check for length and repetition. It compiles and works as expected, however, occasionally, I will get a StackOverflowError while it is running. Here is the block of code where it seems to be having a problem with:
//ensures that generated pattern is four digits long
public void randomCheck(){
int patternNum = Integer.parseInt(pattern);
if(patternNum<1000){
numGen();
}
else{
repeatCheck();
}
}
//ensures that pattern is unique
public void repeatCheck(){
solutionNumber();
if((secondSolnDigit==firstSolnDigit)||(firstSolnDigit==thirdSolnDigit)||
(firstSolnDigit==fourthSolnDigit)||(secondSolnDigit==thirdSolnDigit)||
(secondSolnDigit==fourthSolnDigit)||(thirdSolnDigit==fourthSolnDigit)){
numGen();
}
else{
return pattern;
}
}
//generates random number
public void numGen();{
Random rand = new Random();
int randomNum = rand.nextInt(10000);
String patternString = Integer.toString(randomNum);
pattern = patternString;
randomCheck();
}