我正在尝试使用以下代码生成10位唯一随机数.根据我的要求,我必须创建大约5000个唯一数字(ID).这没有按预期工作.它还会生成-ve数字.此外,有时生成的数字中缺少一个或两个数字,导致8或9个数字不是10.
public static synchronized List generateRandomPin(){
int START =1000000000;
//int END = Integer.parseInt("9999999999");
//long END = Integer.parseInt("9999999999");
long END = 9999999999L;
Random random = new Random();
for (int idx = 1; idx <= 3000; ++idx){
createRandomInteger(START, END, random);
}
return null;
}
private static void createRandomInteger(int aStart, long aEnd, Random aRandom){
if ( aStart > aEnd ) {
throw new IllegalArgumentException("Start cannot exceed End.");
}
//get the range, casting to long to avoid overflow problems
long range = (long)aEnd - …Run Code Online (Sandbox Code Playgroud) java ×1