商城首页欢迎来到中国正版软件门户

您的位置:首页 >java如何使用Math.random()生成随机数

java如何使用Math.random()生成随机数

  发布于2023-04-25 阅读(0)

扫一扫,手机访问

使用Math.random()生成随机数

直接贴几个小方法

/**
* 获取0.0-1.0之间的随机小数
*/
private double test1() {
    double num = Math.random();
    return num;
}
/**
* 获取两个数之间的随机小数
*/
private double test2(int min, int max) {
    return min + Math.random() * (max - min);
}
/**
* 获取两个数之间的随机整数
*/
private int test3(int min, int max) {
    return (int) (min + Math.random() * (max - min));
}
本文转载于:https://www.yisu.com/zixun/485523.html 如有侵犯,请联系zhengruancom@outlook.com删除。
免责声明:正软商城发布此文仅为传递信息,不代表正软商城认同其观点或证实其描述。

热门关注