PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

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

WBOY
WBOY 转载
2023-05-11 15:40:12 784浏览

使用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));
}

以上就是java如何使用Math.random()生成随机数的详细内容,更多请关注php中文网其它相关文章!

声明:本文转载于:亿速云,如有侵犯,请联系admin@php.cn删除