温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

java random类

发布时间:2020-08-06 18:23:47 来源:网络 阅读:151 作者:wx5d21d5e6e5ab1 栏目:编程语言
    Random rand=new Random();

    System.out.println(rand.nextDouble());    //生成0到1区间的随机double类型的数
    System.out.println(rand.nextInt());       //生成int范围内的随机数
    System.out.println(rand.nextFloat());     //生成0到1区间内的随机float类型的数
    System.out.println(rand.nextBoolean());   //生成随机布尔值
    System.out.println(rand.nextInt(10));     //生成0到10的随机int类型的数
    System.out.println(20+rand.nextInt(10));  //生成0到30的随机int类型的数
    System.out.println(20+(int)(rand.nextFloat()*10));   //与上面相同
    System.out.println(20+(int)(rand.nextDouble()*10));   //与上面相同

    涉及浮点类型的,范围都在0到1
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI