public static void main(String[] args) {
// TODO Auto-generated method stub
Integer len =7;
Random random = new Random();
for(int i=0;i<1000;i++){
int r = random.nextInt(len);
System.out.println(r);
}
}
产生7以内的整数,0,1,2,3,4,5,6
此外可以比较下
Java: Random.nextInt() 和Math.random()的区别 -
// TODO Auto-generated method stub
Integer len =7;
Random random = new Random();
for(int i=0;i<1000;i++){
int r = random.nextInt(len);
System.out.println(r);
}
}
产生7以内的整数,0,1,2,3,4,5,6
此外可以比较下
Java: Random.nextInt() 和Math.random()的区别 -