learning java Random 和 ThreadLocalRandom类

        var rand = new Random();
        System.out.println(rand.nextBoolean());
        System.out.println(rand.nextInt());
        System.out.println(rand.nextDouble());
        System.out.println(rand.nextGaussian());
        var buffer = new byte[16];
        rand.nextBytes(buffer);
        System.out.println(Arrays.toString(buffer));
        System.out.println(rand.nextLong());


        ThreadLocalRandom rand1 = ThreadLocalRandom.current();
        int val1 = rand1.nextInt(10, 30);
        double val2 = rand1.nextDouble(2,10);
        System.out.println(val1);
        System.out.println(val2);

output:

true
1325516222
0.6200486521064013
-0.9852917147015956
[86, -85, -56, 53, -14, -10, 8, -15, 25, 25, 35, -128, 90, -25, -38, -80]
5564050155834332951
17
7.958409014368988

  

posted @ 2019-07-25 16:42  嵌入式实操  阅读(150)  评论(0编辑  收藏  举报