Random random = new Random(); int iRand1 = random.nextInt(999999);//前几个可能为0 int iRand2 = 100000 + random.nextInt(899999);//前几个可能为0 ...//use it
敲错了,更正: int iRand2 = 100000 + random.nextInt(899999);//首位不为0
class RandomUtil{ private long i = 100000; public long next(){ return i++; } } 如果有多线程的话next()方法要同步
class RandomUtil{ private long i = 100000; public long next(){ if(i==1000000) System.out.print("将出现重复数据")//如果你调了900000次这个方法,用random也无法避免出现重复数字。 return i++; } }
class RandomUtil{ private long i = 100000; public long next(){ if(i==1000000){ i = 1000000; System.out.print("将出现重复数据")//如果你调了900000次这个方法,用random也无法避免出现重复数字。} return i++; } }
int iRand1 = random.nextInt(999999);//前几个可能为0
int iRand2 = 100000 + random.nextInt(899999);//前几个可能为0
...//use it
int iRand2 = 100000 + random.nextInt(899999);//首位不为0
private long i = 100000;
public long next(){
return i++;
}
}
如果有多线程的话next()方法要同步
private long i = 100000;
public long next(){
if(i==1000000)
System.out.print("将出现重复数据")//如果你调了900000次这个方法,用random也无法避免出现重复数字。
return i++;
}
}
private long i = 100000;
public long next(){
if(i==1000000){
i = 1000000;
System.out.print("将出现重复数据")//如果你调了900000次这个方法,用random也无法避免出现重复数字。}
return i++;
}
}
nieyc() 的方法不错