Really strange for recursive
Hi guys,
I am using jdk1.5.0_05 under windows xp. My code is below:
import org.apache.commons.lang.RandomStringUtils;
public class StringUtilsTest {
public static void main(String[] args) {
int y=0;
for(int i = 0;i<10;i++){
String s = getRandomNumeric();
System.out.println("s = "+s);
}
}
private static String getRandomNumeric(){
System.out.println("start");
String s1 = RandomStringUtils.randomNumeric(4);
if(Integer.parseInt(s1) < 1000){
getRandomNumeric();
}
return s1;
}
}
and the output i got is:
start
s = 6511
start
s = 8869
start
s = 6088
start
start
s = 0068
start
s = 7693
start
s = 2637
start
s = 4096
start
s = 6396
start
s = 2318
start
s = 9624
As u notice that when the 4th time the getRandomNumeric() is called, the value is less than 1000 so it recurse again. But the value return still < 1000, which is 0068. All I want is the get a random number, which is not < 1000. Please help, Thanks !
regards,
Mark

