《Java编程技巧1001条》353条:求随机浮点数
2017-12-19 08:06
399 查看
《Java编程技巧1001条》353条:求随机浮点数
353Creating Random Floating-Point numbers Using the Math Class 353 利用 Math 类创建随机浮点数 Depending on your programs purpose, you mayneed to generate one or more random numbers. In such cases, your programs canuse the Math class random function. The format of
the random function is asfollows: 根据你的程序的用途,你有可能需要生成一个或多个随机数. 在这种情况下,你可使用 Math 类提供的 random 方法.random 函数的格式如下: public static synchronized double random();The following statements illustrate the use of the random method: 以下语句说明了 random 方法的用法: double rand; rand
= Math.random(); {kaj verifythis statementdoes not seem right} 【译注】但我不知道 Kai 所指的似乎不正确的地方在哪里? The random function returns a value in therange 0 to 1.0. By multiplying the functions result by a value such as 100 or1000, your programs can change the range of
values. 随机函数返回的值在 0 到 1.0 范围内. 将所得函数值乘以 100 或 1000 等就可以改变(扩 大)所得结果值的范围.
353Creating Random Floating-Point numbers Using the Math Class 353 利用 Math 类创建随机浮点数 Depending on your programs purpose, you mayneed to generate one or more random numbers. In such cases, your programs canuse the Math class random function. The format of
the random function is asfollows: 根据你的程序的用途,你有可能需要生成一个或多个随机数. 在这种情况下,你可使用 Math 类提供的 random 方法.random 函数的格式如下: public static synchronized double random();The following statements illustrate the use of the random method: 以下语句说明了 random 方法的用法: double rand; rand
= Math.random(); {kaj verifythis statementdoes not seem right} 【译注】但我不知道 Kai 所指的似乎不正确的地方在哪里? The random function returns a value in therange 0 to 1.0. By multiplying the functions result by a value such as 100 or1000, your programs can change the range of
values. 随机函数返回的值在 0 到 1.0 范围内. 将所得函数值乘以 100 或 1000 等就可以改变(扩 大)所得结果值的范围.
相关文章推荐
- 《Java编程技巧1001条》 第346条:浮点数向上向下舍入方法
- 《Java编程技巧1001条》354条:了解伪随机与真随机
- 《Java编程技巧1001条》360-373条:用日期函数获得当前日期
- 《Java编程技巧1001条》第603条: 使用双缓冲器改进动画
- 《Java编程技巧1001条》第375条: 使用DOS下的 TZ 环境变量,
- 《Java编程技巧1001条》第604条:了解图像的观察器
- 《Java编程技巧1001条》第379条: 初始化基本类型数组
- 《Java编程技巧1001条》第373条: 了解不同的日期标准,
- 《Java编程技巧1001条》 第605条: 检测图像装入过程
- 《Java编程技巧1001条》第606条: 获得图像的大小尺寸
- 《JAVA编程技巧1001条》第334条:数学函数 求绝对值.
- 《Java编程技巧1001条》 第345条:使用ceil方法
- 《JAVA编程技巧1001条》第335条:数学函数 SQRT.
- 《Java编程技巧1001条》357条:用高斯分布建立随机数
- 《Java编程技巧1001条》第607条: 利用MediaTraker预装图像
- 《JAVA编程技巧1001条》第337条:数学函数 SIN。
- 《Java编程技巧1001条》第608条: 在装入图像时设置时间限制
- 《JAVA编程技巧1001条》第338条:数学函数 TAN
- 《Java编程技巧1001条》第592条: 播放声音剪辑
- 《JAVA编程技巧1001条》第339条:数学函数 ARCCOS