public static void main(String[] args) {
Random r = new Random(1000);
System.out.println(r.nextInt());
System.out.println(r.nextInt());
System.out.println(r.nextInt());
System.out.println(r.nextInt());
System.out.println(r.nextInt(100));
System.out.println(r.nextInt(100));
System.out.println(r.nextInt(100));
System.out.println(r.nextInt(100));
}
2、不 同 Random对象调用next()方法,相同调用next()方法次数得出的随机数是相同的。(要保证2个next()的参数相同)例二: public class Test {
public static void main(String[] args) {
Random r1 = new Random(1000);
Random r2 = new Random(1000);
System.out.println("r1"+" "+"r2");
for (int i = 1; i <10; i++) {
System.out.println(r1.nextInt(100)+" "+r2.nextInt(100));
}
}
}