Java.lang.StrictMath.random() 方法
描述
java.lang.StrictMath.random() 方法返回一个带正号的双精度值,大于或等于 0.0 且小于 1.0。此方法已正确同步以允许超过 一根线。
声明
以下是 java.lang.StrictMath.random() 方法的声明。
public static double random()
参数
NA
返回值
此方法返回大于等于 0.0 且小于 1.0 的伪随机 double。
异常
NA
示例
下面的例子展示了 java.lang.StrictMath.random() 方法的使用。
package com.tutorialspoint;
import java.lang.*;
public class StrictMathDemo {
public static void main(String[] args) {
/* returns a double value with a positive sign,
greater than or equal to 0.0 and less than 1.0 */
double randomValue = StrictMath.random();
System.out.println("1st randomly generated number = "+ randomValue);
System.out.println("2nd randomly generated number = "+ StrictMath.random());
System.out.println("3rd randomly generated number = "+ StrictMath.random());
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
1st randomly generated number = 0.9920868657769093 2nd randomly generated number = 0.15952532993970858 3rd randomly generated number = 0.26097639244001813

