Random r = new Random(); for (int i = 0; i < 10; i++) { int a = r.nextInt(100);//生成在0到n范围内的随机数,包含0不包含n System.out.print(a + " "); }
Random r1 = new Random(1000); Random r2 = new Random(1000);//使用相同的种子 System.out.println(r1.nextInt()); System.out.println(r2.nextInt());//结果一样