Random():创建一个新的随机数生成器。
Random(long seed):使用单个种子创建一个新的随机数生成器。
如果seed相同的话,前后两次的随机数会一致!!
int[] nums1 = new int[8]; int[] nums2 = new int[8]; Random random = new Random(47); for(int i=0;i<8;i++){ nums1[i]=random.nextInt(55); } Random random2 = new Random(47); for(int i=0;i<8;i++){ nums2[i]=random2.nextInt(55); } for(int i :nums1) System.out.print(i+" "); // System.out.println(); for(int j: nums2) System.err.print(j+" ");
输出结果:
38 25 43 35 51 51 17 38
38 25 43 35 51 51 17 38
转载请注明原文地址: https://ju.6miu.com/read-676382.html