java实现可重复的随机数

x33g5p2x  于2021-11-24 转载在 Java  
字(0.6k)|赞(0)|评价(0)|浏览(528)
package com.fastone.www.javademo.randomtest;

import java.util.Random;

/**
 *
 * 生成相同的随机数
 * @program: javademo
 * @description: random测试
 * @author: sunyuhua
 * @create: 2021-11-24 12:55
 **/
public class TestRandom {
 public static void main(String[] args) {
  Random rnd = new Random(20211026);
  for(int i=0;i<5;i++){
   System.out.println(rnd.nextInt(100)+" ");
  }

  System.out.println("--------");
  Random rnd2=new Random();
  rnd2.setSeed(200);
  for(int i=0;i<5;i++){
   System.out.println(rnd2.nextInt(100)+" ");
  }

 }
}
已连接到目标 VM, 地址: ''127.0.0.1:54301',传输: '套接字''
95 
14 
30 
42 
45 
--------
29 
41 
66 
33 
72 
与目标 VM 断开连接, 地址为: ''127.0.0.1:54301',传输: '套接字''

相关文章

微信公众号

最新文章

更多