一 要求随机生成一个字符串, 要求该字符串不在原来的字符串列表当中即可,再将生成的字符串添加到列表中, 生成新的字符串列表
public class Test {
public static void main(String[] args) {
List<String> macTypeIdList = new ArrayList<>();
macTypeIdList.add("500396");
macTypeIdList.add("500903");
macTypeIdList.add("500749");
macTypeIdList.add("500808");
macTypeIdList.add("500101");
String typeId ="000";
String supplierId = "500";
Random random = new Random();
while (true){
int serialNum = random.nextInt(900) + 100;
typeId = supplierId + serialNum;
if (!macTypeIdList.contains(typeId)){
System.out.println(typeId);
System.out.println(macTypeIdList);
break;
}
}
}
}
二 要求随机一个Long类型的设备类型id, 要求该数字不在原来的List设备Id列表当中即可. 设备类型Id = 500 + 一个三位数的随机数, 新生成的设备id添加到列表当中,形成新的列表
代码: