Java中Random的种子数用法

2021年9月26日 2092点热度 3人点赞 0条评论
public class DemoApplicationTests {

    @Test
    public void contextLoads() {
        Random random = new Random(47);
        int aa = random.nextInt(100);
        System.out.println(aa+"------");

        for (int i=0;i<10;i++){
            Random random00 = new Random(47);
            int bb = random00.nextInt(100);
            System.out.println(bb);
        }
    }
}

输出结果:
58------
58
58
58
58
58
58
58
58
58
58

public class DemoApplicationTests {

    @Test
    public void contextLoads() {
        Random random = new Random(47);
        int aa = random.nextInt(100);
        System.out.println(aa+"------");

        for (int i=0;i<10;i++){
            Random random00 = new Random(47);
            int bb = random00.nextInt(10000);
            System.out.println(bb);
        }
    }
}

输出结果:
58------
9258
9258
9258
9258
9258
9258
9258
9258
9258
9258

小小调酒师

此刻打盹,你将做梦; 此刻学习,你将圆梦。 个人邮箱:shellways@foxmail.com

文章评论