java实现可重复的随机数

x33g5p2x  于2021-11-24 转载在 Java  
字(0.6k)|赞(0)|评价(0)|浏览(802)
  1. package com.fastone.www.javademo.randomtest;
  2. import java.util.Random;
  3. /**
  4. *
  5. * 生成相同的随机数
  6. * @program: javademo
  7. * @description: random测试
  8. * @author: sunyuhua
  9. * @create: 2021-11-24 12:55
  10. **/
  11. public class TestRandom {
  12. public static void main(String[] args) {
  13. Random rnd = new Random(20211026);
  14. for(int i=0;i<5;i++){
  15. System.out.println(rnd.nextInt(100)+" ");
  16. }
  17. System.out.println("--------");
  18. Random rnd2=new Random();
  19. rnd2.setSeed(200);
  20. for(int i=0;i<5;i++){
  21. System.out.println(rnd2.nextInt(100)+" ");
  22. }
  23. }
  24. }
  1. 已连接到目标 VM, 地址: ''127.0.0.1:54301',传输: '套接字''
  2. 95
  3. 14
  4. 30
  5. 42
  6. 45
  7. --------
  8. 29
  9. 41
  10. 66
  11. 33
  12. 72
  13. 与目标 VM 断开连接, 地址为: ''127.0.0.1:54301',传输: '套接字''

相关文章

最新文章

更多