获得指定数字范围的随机数
public static String getRandom(int min, int max){
Random random = new Random();
int s = random.nextInt(max) % (max - min + 1) + min;
return String.valueOf(s);
}
public static void main(String[] args) {
for (int i=0;i<20;i++){
String random = getRandom(0, 5);
System.out.println(random);
}
}
来源:CSDN
作者:qq_31683775
链接:https://blog.csdn.net/qq_31683775/article/details/104307295