您的位置:首页 > 编程语言 > Java开发

《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 等就可以改变(扩 大)所得结果值的范围.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: